CString 和 const char* 的相互转化(UNICODE)。

const char* c;
c = "abcdef";
CString s;
int len = strlen(c);
TCHAR* c1 = (TCHAR*)malloc(sizeof(TCHAR)*len);
MultiByteToWideChar( CP_ACP , 0 , c , len+1 , c1 , len+1);
s.Format(L"%s",c1);

--------------

    CString str(L"This is a test");
int len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , NULL , 0 , NULL , NULL );
char* pAscii =new char[len+1];
len
= WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , pAscii , len +1 , NULL ,NULL );
pAscii[len]
= 0;

 const char* xxx = (const char*)pAscii;

 char a = xxx[0];

char b = xxx[1];
char c = xxx[2];
char d = xxx[3];
原文地址:https://www.cnblogs.com/aoyihuashao/p/1708439.html