16,473
社区成员
发帖
与我相关
我的任务
分享
CString A;
char * p=NULL;
int wLen = A.GetLength()+1;
int uLen = WideCharToMultiByte(CP_UTF8,0,(LPCTSTR)A,wLen,NULL,0,NULL,NULL);
p=new char[uLen];
WideCharToMultiByte(CP_UTF8,0,(LPCTSTR)A,wLen,p,uLen,NULL,NULL);
....
....
delete [] p;
// Do not assert in this function since it is used by the asssertion code!
std::string SysWideToUTF8(const std::wstring& wide) {
return SysWideToMultiByte(wide, CP_UTF8);
}
// Do not assert in this function since it is used by the asssertion code!
std::string SysWideToMultiByte(const std::wstring& wide, uint32 code_page) {
int wide_length = static_cast<int>(wide.length());
if (wide_length == 0)
return std::string();
// Compute the length of the buffer we'll need.
int charcount = WideCharToMultiByte(code_page, 0, wide.data(), wide_length,
NULL, 0, NULL, NULL);
if (charcount == 0)
return std::string();
std::string mb;
mb.resize(charcount);
WideCharToMultiByte(code_page, 0, wide.data(), wide_length,
&mb[0], charcount, NULL, NULL);
return mb;
}