It declares a typedef of type basic_string<char, char_traits<char>, allocator<char> > named string. What specific aspect of it do you want to know about?
It defines a type under the name string. That type is an instantiation of the basic_string class template parameterized by types char, chart_traits and allocator (the last two are also class templates parameterized by type char).
Basically, you need knowledge of C++ templates and the typedef keyword in order to understand that. Check them in your favorite C++ book or on the internet.
small point but typedef does not define a type. classes and structs define types. A typedef creates an alias for a type so you can refer to a long-windedly-named-type by its alias.
Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
Always use [code] code tags [/code] to make code legible and preserve indentation.
Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.
It declares a typedef of type basic_string<char, char_traits<char>, allocator<char> > named string. What specific aspect of it do you want to know about?
Thanks All.
I want to know exactly what happens when we define a variable with type "basic_string<char, char_traits<char>, allocator<char> >" or simply "string".
I what to know this line :>>> basic_string<char, char_traits<char>, allocator<char> >
Last edited by soroush_vs; March 13th, 2009 at 02:53 PM.
That's exactly what you said before. You haven't elaborated any on your confusion.
Originally Posted by Russco
small point but typedef does not define a type. classes and structs define types. A typedef creates an alias for a type so you can refer to a long-windedly-named-type by its alias.
Technically, it is a definition (as opposed to a declaration).
I want to know what this data type store data .How this string store information and how we can manipulate it?
I want to know why we use this instead of a simple char or TCHAR or CString or other simplest forms.
I what to know why this defines at this such a form : basic_string<char, char_traits<char>, allocator<char> >
I what to know this line of code means that string is really a char or char_traits or allocator or something other?
How compiler deal with it?When compiler goes into the source code and saw a "string" then change it into basic_string<char, char_traits<char>, allocator<char> > then it means that this is a data type? like this?
I want to know what this data type store data .How this string store information and how we can manipulate it?
Get a C++ book and read about std::string.
I want to know why we use this instead of a simple char or TCHAR or CString or other simplest forms.
A char is a single character. A TCHAR is also a single character and it only works for Windows. A CString only works for MFC. What if I don't work in Windows, and I need a string? Use std::string.
I what to know why this defines at this such a form : basic_string<char, char_traits<char>, allocator<char> >
Because a std::string is really a template.
I what to know this line of code means that string is really a char or char_traits or allocator or something other?
Get a book on C++ and templates. A basic_string<> is a general template class that handles sequences of characters. A character can be an 8 bit character, 16-bit character, or any type that works. A sequence of char types is a basic_string<char>.
The char_traits<char> is another template that tells the basic_string<> template how to handle the "char" in certain places in the basic_string template function.
The allocator template tells how to allocate memory when the basic_string template asks for memory.
Now it's your turn to do the research and learn C++, as all of these questions are answered in depth and in full in C++ books, and by learning the C++ language. Randomly just looking at C++ source code, and then asking questions is not the way to learn the language.
Bookmarks