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

来源:互联网 发布:php array push 键值 编辑:程序博客网 时间:2024/05/22 20:28
以下是一个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);

 

HJAA.NET原创,转载请附带本文链接:http://www.hjaa.net/articles/2012/09/1083.html
原创粉丝点击