加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 09:18:11 所属栏目:百科 来源:网络整理
导读:1.我是用rapidxml文件读取utf-8格式的xml,但是显示乱码。我们需要把读出来的内容转为GBK格式,则能正常显示。 char * utf82gbk(char* strutf) { //utf-8转为Unicode int size = MultiByteToWideChar(CP_UTF8,strutf,-1,NULL,0); WCHAR *strUnicode = new WC

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

char * utf82gbk(char* strutf)

{

//utf-8转为Unicode

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

MultiByteToWideChar(CP_UTF8,strUnicode,size);


//Unicode转换成UTF-8;

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

return strGBK;

}


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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读