The prototype of the 1.string class member function c_str ():
Const Char *c_str ()const; // returns a null-terminated C string
The 2.c_str () function returns a pointer to a regular C string that is the same as the object of the string class, and is able to convert a string object to the style of a string in C by using the C_STR () function of the string class;
The C_STR () function returns a pointer to the normal C string with the same contents as this string string.
This is to be compatible with the C language, there is no string type in C, so the string object must be converted to a string style in C by using the member function C_str () of the String class object.
Note: Be sure to use the strcpy () function and so on to manipulate the pointer returned by the method C_str ()
- For example: It's best not to:
Char*string s="1234"= S.c_str// c The last point of the content is garbage, because S object is destructor, its content is processed
Char c[]; string s="1234"; strcpy(c,s.c_str());
So that there is no error, C_STR () returns a temporary pointer that cannot be manipulated
Excerpt from: http://blog.csdn.net/zhangfn2011/article/details/6364750
C_str ()