What's the difference between std::string
and std::basic_string
? And why are both needed?
There is no functionality difference between string and std::string because they're the same type.
std::string offers a very different and much expanded interface compared to std::vector<> . While the latter is just a boring old sequence of elements, the former is actually designed to represent a string and therefore offers an assortment of string-related convenience functions.
std::string class in C++ C++ has in its definition a way to represent a sequence of characters as an object of the class. This class is called std:: string. String class stores the characters as a sequence of bytes with the functionality of allowing access to the single-byte character.
You don't need to use using namespace std; . You can qualify the namespace directly with the type. Just write std::string s; . @Martin: string is not a template class, basic_string is.
std::basic_string
is a class template for making strings out of character types, std::string
is a typedef
for a specialization of that class template for char
.
std::string
is an instantiation of std::basic_string<T>
:
typedef std::basic_string<char> string
std::basic_string
is necessary to have a similar interface for all type of strings (wstring
for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With