1、将char*类型字符串转换为CString
char sz[128];
CString str;
str.Format("%s",sz);
2、将CString类型字符串转换为char*
CString str;
int nLength = str.GetLength();
char* sz = new char[nLength];
sz = str.GetBuffer(0);
3、当CString表示的是Unicode字符串时,需要使用WideCharToMultiByte函数将Unicode字符串转换成ANSI字符串
TCHAR* szUnicode = _T("Hello World");
int iLength = lstrlen(szUnicode);
char* szAnsi = new char[iLength];
WideCharToMultiByte(CP_ACP, 0, szUnicode,
-1, szAnsi, 256, NULL, NULL);
4、ANSI字符串转换为Unicode字符串
char* szANSI = "Hello World";
int iLength = strlen(szANSI);
TCHAR* szUnicode = new TCHAR[iLength];
MultiByteToWideChar(CP_ACP, 0, szANSI,
-1, szUnicode, iLength);