您的位置:首页 > 编程语言 > C语言/C++

UNICODE 下CString与char*的相互转化

2016-06-03 14:57 411 查看
CString  转化为char*

int n = cstr.GetLength();
int len =WideCharToMultiByte(CP_ACP,0,cstr,cstr.GetLength(),NULL,0,NULL,NULL);
char * p = new char[len+1];
WideCharToMultiByte(CP_ACP,0,cstr,cstr.GetLength() + 1 ,p,len+ 1 ,NULL,NULL);
p[len+1]= '/0';

char*  转化为CString
void charToCString(char * ch, CString &cstr)
{
int nLen = strlen(ch) + 1;
int nwLen = MultiByteToWideChar(CP_ACP, 0, ch, nLen, NULL, 0);
TCHAR lp[256];
MultiByteToWideChar(CP_ACP, 0, ch, nLen, lp, nwLen);
cstr = lp;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++