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;