wchar_t*转std::string
std::string wideChar2string(wchar_t* pWCStrKey){
std::wstring wstr(pWCStrKey);
std::string str(wstr.length(), ' ');
std::copy(wstr.begin(), wstr.end(), str.begin());
return str;
}
上面的中文乱码。
std::string wideChar2string(wchar_t* unicode)
{
int len;
len = WideCharToMultiByte(CP_UTF8, 0, unicode, -1, NULL, 0, NULL, NULL);
char* szUtf8 = (char*)malloc(len + 1);
memset(szUtf8, 0, len + 1);
WideCharToMultiByte(CP_OEMCP, 0, (const wchar_t*)unicode, -1, szUtf8, len, NULL, NULL);
//WideCharToMultiByte(CP_UTF8, 0, (const wchar_t*)unicode, -1, szUtf8, len, NULL, NULL);
return szUtf8;
std::string str1(szUtf8);
return str1;
}
页:
[1]