UTF8转GBK
在解析读取tinyxml时候,发现读取汉字都是乱码,所以需要转成GBK
static wstring ConvertUTF8toGBK(const char * strUTF8)
{
int len = MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)strUTF8, -1, NULL,0);
TCHAR * wszUtf8 = new TCHAR[len+1];
wcscpy(wszUtf8, _T(""));
MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)strUTF8, -1, wszUtf8, len);
wstring strTemp(wszUtf8);
delete wszUtf8;
return strTemp;
}
使用:
while(NULL != pChildNode) //循环遍历子节点,循环到子节点为空 截止。
{
pAttr = pChildNode->FirstAttribute();
strcpy_s(name, pAttr->Value());
stringInfo.strID = atoi(name);
stringInfo.str = ConvertUTF8toGBK(pChildNode->FirstChild()->Value());
pChildNode = pChildNode->NextSiblingElement();
m_stringMap.insert(String_Data(stringInfo.strID, stringInfo.str.c_str()));
}