Hello all!

I am working through a book here and it says that there is a class-template "basic_string" that is used in the namespace std as typedef basic_string<char> string; to create an alias for the "string" type.

However, I know that there is a header file <string> for the declaration of the string class... so what's the difference between the two?

And when should I rely on namespace std to define string as an alias vs importing the <string> file?

Thanks to all in advance!

string is defined in <string> and the defenition of string is typedef basic_string<char> string;. string is just a typdef and there is no actual string class in the standard. Whenever you want to use a std::string then you need to #include <string>

Edited 1 Year Ago by NathanOliver

So in other words... if I want to use string methods, I #include <string> right? Just checking.

Define by what you mean with:

if I want to use string methods, I #include <string> right?

If you want to use anything release to a std::string or std::wstring then you need <string>. If you want to use things like strcmp(), strncat() and other from the C library they are in <cstring> and/or <string.h>

Two definitions string in formal language theory and computer programming, string concatenation is the operation of joining character strings end-to-end.
string use methods, #include <string> right.

@nathan.pavlovsky All member functions of std::string reside in the <string> header. Here is a good reference that shows you everything in <string>

This article has been dead for over six months. Start a new discussion instead.