`
linyoman
  • 浏览: 5499 次
  • 性别: Icon_minigender_1
  • 来自: 广西
文章分类
社区版块
存档分类
最新评论

C++ \u中文乱码解决办法

 
阅读更多
以下是一个c++ dll jsoncpp解析有\u中文json文件的例子:
std::string showname = rootOne["showname"].asString();
int len=strlen(showname.c_str())+1;
char outch[MAX_PATH];
WCHAR * wChar=new WCHAR[len];
wChar[0]=0;
MultiByteToWideChar(CP_UTF8, 0, showname.c_str(), len, wChar, len);

 

WideCharToMultiByte(CP_ACP, 0, wChar, len, outch , len, 0, 0);
delete [] wChar;
char* pchar = (char*)outch;
这样就得到一个char * 可用于其他的转换
如果要把pchar显示到控件上(比如ListView):
int len=strlen(pchar)+1;
WCHAR outName[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, pchar, len, outName, len);
ListView_SetItemText(hWndListView, index, 2, outName);
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics