What's the difference between std::string and std::basic_string? And why are both needed?
What's the difference between std::string and std::basic_string? And why are both needed?
Just a small addition to whatever everyone else answered. As std::string is a specialization of basic_string it also default some other parameters except the char type .A basic_string can have a custom char type (e.g. basic_string can have wide_chars ) , a custom char_trait (e.g. basic_string can have wide chars but support every operation of normal chars) ,and a custom allocator ( a basic_string can have some extra infos packed with it for a custom debugger or a static memory management).
The std::string defaults all this parameters to reasonable values as on most cases you only need an std::string and that is it's usefulness. On the other hand whenever you need something more custom you have std::basic_string. So both have their different purposes