rapidxml读取utf-8 格式xml乱码问题(utf-8格式转GBK)

来源:互联网 发布:ubuntu新立得安装命令 编辑:程序博客网 时间:2024/05/01 09:37

1.我是用rapidxml文件读取utf-8格式的xml,但是显示乱码。我们需要把读出来的内容转为GBK格式,则能正常显示。

char * utf82gbk(char* strutf)

{

//utf-8转为Unicode

int size = MultiByteToWideChar(CP_UTF8, 0, strutf, -1, NULL, 0);
WCHAR   *strUnicode = new   WCHAR[size];

MultiByteToWideChar(CP_UTF8, 0, strutf, -1, strUnicode, size);


//Unicode转换成UTF-8;

int i = WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, NULL, 0, NULL, NULL);
char   *strGBK = new   char[i];
WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, strGBK, i, NULL, NULL);

return strGBK;

}


2.使用很简单cout << filepath->name() << ":" << utf82gbk( filepath->value()) << endl;

0 0
原创粉丝点击