CString转string:
CString cstr = L"CString2string";
string str = CW2A(cstr);
string转char*
string str = "str2char*";
const char* strc = str.c_str();
CString转char*:
//1.直接转化:
CString cstr = L"CString2char*";
DWORD dwNum = WideCharToMultiByte(CP_OEMCP, NULL, cstr, -1, NULL, NULL, 0, NULL);
char *strc = new char[dwNum];
WideCharToMultiByte(CP_OEMCP, NULL, cstr, -1, strc, dwNum, 0, NULL);
//2.间接转化:
CString cstr = L"CString2char*";
string str = CW2A(cstr);
const char* strc = str.c_str();
char*转string:
char* strc = "char*2string";
string str(strc);
string转CString:
string str = "string2CString";
CString cstr(str.c_str());
char*转CString:
char* strc = "char*2CString";
CString cstr(strc);