在解析读取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()));
 }

相关文章:

  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-11-30
猜你喜欢
  • 2022-01-10
  • 2021-10-07
  • 2022-12-23
  • 2021-06-09
  • 2021-11-30
  • 2022-02-09
相关资源
相似解决方案