(1) In C ++, the function string (char *) is required to convert char * to string, for example, char * Ch = "ABC"; string STR = string (CH ); (2) if the content is not changed when char * is passed, use the const char * (3) string function to convert char * as much as possible: c_str is used to obtain the address of the string in the memory. For example, char * pS; string CH = "AAA"; PS = CH. c_str (); Note: If ch changes, PS also changes. (4) I checked it online just now. The original method (3) is not good. We should do this: char * CP = new char [edit1-> text. length () + 1];
Strcpy (CP, edit1-> text. c_str (); cause: c_str () is used to obtain the temporary address of a string. The reason is that it is a temporary address because ch is a dynamic string and the value of each string changes, the memory will be re-allocated, so the address will change dynamically. Therefore, c_str () should be out-of-the-box. Pay special attention, do not use the pointer obtained by c_str to rewrite the string value of Ch. Otherwise, you will regret it.
(5) Try not to use the pointer to control the array, because the array can save the first address information, but the pointer cannot. Especially when operating on the string, pointers are usually sorted in reverse order. (6) The string type is "an array of the appropriate number of const characters", that is, the const char [] type.