char* turn into CString |
Ø can be directly constructed as follows: char * p = "Test"; CString str (p); Ø You can use the member function format as follows: char* p = "Test"; CString str; Str. Format ("%s", p); |
char* Convert to string |
Direct from C har* constructs a string to chat* sz= "CWSASD"; string S1 (SZ); |
string convert into char*
|
Char *TP = const_cast<char*> (S1.c_str ()); |
string convert into CString
|
CString str2; Str2. Format (L "%s", S1.c_str ()); |
CString convert into char*
|
CString Str ("test"); int Len=str.getlength (); Char *cstr=new char[len+1]; cstr[len]=0; WideCharToMultiByte (CP_OEMCP, 0, str,-1, CStr, len, null, NULL); |
CString Convert to String
|
Method: "First convert CString to char* and then construct string from char*" CString t = CString (s[i]); int Len=t.getlength (); Char *cstr=new char[len+1]; cstr[len]=0; WideCharToMultiByte (CP_OEMCP, 0, T,-1, CStr, len, null, NULL); String S1 (CStr); |
Reprinted from Http://blog.csdn.net/chu_qun/archive/2008/09/19/2953377.aspx