What's the difference between std::string and std::basic_string? And why are both needed?

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 Yes they are both needed (or at least required by the standard).

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. Yes they are both needed (or at least required by the standard).

Std::string is an instantiation of std::basic_string: typedef std::basic_string string. Std::basic_string is necessary to have an similar interface for all type of strings (wstring for example).

7 The proper term is "specialization". String is a specialization of basic_string. – AndreyT Nov 2 '09 at 16:25 1 I guess you could argue about that."specialization" is usually used to indicate inheritance.

A templated {class|function} is instantiated by substituting the template arguments. There is partial template specialization but this isn't used here. – pmr Nov 2 '09 at 17:14 2 Referring to a derived class as a 'specialization' is a less formal use of 'specialization'.

The word 'specialization' isn't used like this at all in the standard (I'm fairly sure), but its used extensively to describe template specialization. The name of a template specialization can be used in contexts that don't force and implicit instantiation so specialization and instantiation are separate concepts.As well as a template specialization (the name of a template with a particular set of parameters), there are also partial specializations (class templates only) and explicit specializations. – Charles Bailey Nov 2 '09 at 17:45 1 @Jerry Coffin: std::string is a typedef for a specialization of a template.

How is the use of "specialization" misleading? – Charles Bailey Nov 2 '09 at 17:53 1 @Charles: it's misleading because (with templates), "specialization" normally refers to either partial specialization, or explicit specialization, not a typedef for what will end up as a simple instantiation. – Jerry Coffin Nov 2 '09 at 18:01.

A std::string is an instantiation of the std::basic_string template with a type of char. You need both so that you can make strings of things besides char, such a std::basic_string for a string of wide characters. Or if you want a string with 32 bit elements, std::basic_string.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions