char * CSelectFile::GB2312ToUtf8(const char * gb2312)
{
int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1);
MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);
len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);
char* tempStr = new char[len + 1];
memset(tempStr, 0, len + 1);
WideCharToMultiByte(CP_UTF8, 0, wstr, -1, tempStr, len, NULL, NULL);
if (wstr) delete[] wstr;
return tempStr;
}
uj5u.com熱心網友回復:
...
wchar_t* wstr = new wchar_t[len + 1];
memset(wstr, 0, len + 1); //這里有問題,memset的長度是位元組,wstr的話wchar_t是雙位元組需要乘2, memset(wstr, 0, sizeof(wchar_t)*(len + 1));
...
char* tempStr = new char[len + 1];
memset(tempStr, 0, len + 1); //這里沒問題,因為tempStr是char單位元組
...
可以先把上述有問題的地方改了,然后再發送一遍到linux上看對不對。
uj5u.com熱心網友回復:
這個問題,注意到了,改了,試了一下,還是一樣的,存在亂碼
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/195474.html
標籤:網絡編程
