0

hi guys
i have a little question
i don't understand this line
typedef basic_string <char> string ;
i have searched but can't get it any one can help
ur help will be appreciated

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by firstPerson
0

>i don't understand this line typedef basic_string <char> string;

basic_string class is parameterized by character type. There is no need to use the basic_string template directly. The types string and wstring are typedefs for, respectively, basic_string<char> and basic_string<wchar_t>.

See article.

0

That line is basically creating a new variable type for you called string, the basic_string<char> is something you dont need to worry about, I will just guess though that you included <string> into your program. string is just another way of saying char*, but it is less of an array and more of a vector, at least in my opinion ;). With that line, now you can make something like this:

string mystring = "HelloWorld!\n";
cout << mystring;

Hope that was helpful

- Pranav Sathyanarayanan

0

thanks adatapost and WargRider so much
but the question is about basic string<char>
i am not professional in c++
but all my knowledge
was that we can write typedef int integer
something like this
i know basic string is a class but why we didn't write it in this way

basic_string (char)
and thanks again ur posts were so helpful guys : )

1

Do you know what this means :

typedef unsigned int uInt //?

Do you know what a class is?

Then all this

typedef basic_string <char> string

is, is a typedef for a template class called basic_string;

Its the same as this :

typedef int INT

in concept, but instead of int they substitute it for a template class.

Votes + Comments
Helpful!
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.