本文介绍的是内存中使用tinyxml的中文乱码情况
直接上干货
1、对方发送的utf-8格式数据,本地接收时中文乱码:utf-8 转 unicode即可
wstring UTF8ToUTF16( const char *szIn )
{
wstring strResult;
if( szIn )
{
wchar_t *wszUTF16;
int len = MultiByteToWideChar( CP_UTF8, 0, ( LPCSTR )szIn, -1, NULL, 0 );
wszUTF16 = new wchar_t[len + 1];
memset( wszUTF16, 0, len * 2 + 2 );
MultiByteToWideChar( CP_UTF8, 0, ( LPCSTR )szIn, -1, ( LPWSTR )wszUTF16, len );
strResult = wstring( wszUTF16 );
delete []wszUTF16;
}
return strResult;
}
2、发送给对方时对方中文显示乱码,对方utf-8转unicode也不行,本地需要先转换下再发送
void GBKToUTF8(char* &szOut)
{
char* strGBK = szOut;
int len=MultiByteToWideChar(CP_ACP, 0, (LPCSTR)strGBK, -1, NULL,0);
unsigned short * wszUtf8 = new unsigned short[len+1];
memset(ws