It is often used in the past few days.
Each of these three types has its own advantages. For example, cstring is flexible. It is a common type based on MFC and has the highest security, but has the worst portability. String is an essential type when STL is used, so it must be mastered during Engineering. char * is inseparable from us since learning C language, many APIs use char * as the parameter input. Therefore, it is necessary to master the conversion between the three.
Below I will use a simple illustration to point out the relationship between the three and use the label-based conversion method.
1 string to cstring
Cstring. Format ("% s", String. c_str ());
2 cstring to string
String STR (cstring. getbuffer (Str. getlength ()));
3 string to char *
Char * P = string. c_str ();
4 char * to string
String STR (char *);
5 cstring to char *
Strcpy (char, cstring, sizeof (char ));
6 char * To cstring
Cstring. Format ("% s", char *);
the format method of cstring is very useful. C_str () of string is also very common, but it is the safest to define char as const char * during conversion with char.