您的位置:首页 > 其它

UNICODE下CString 和 const char* 的相互转化

2016-03-08 10:51 381 查看
const char* 转换为 CString:

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 转换为 const char*:
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;

原文地址:http://www.cnblogs.com/aoyihuashao/archive/2010/04/09/1708439.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: