boost读取utf-8编码xml文件

时间:2014-06-11 08:13:42   收藏:0   阅读:730

参照:http://www.cnblogs.com/qicosmos/p/3555668.html

解决boost读取utf-8 xml文件乱码问题.

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void io::read(const string& file)
{
    try
    {
        wifstream f(file);
        locale utf8Locale(locale("chs"), new codecvt_utf8<wchar_t>);
        f.imbue(utf8Locale);
        wptree pt;
        read_xml(f, pt);
        wstring w = pt.get<wstring>(L"class.name");
        string a(w.begin(),w.end());
        wcout.imbue(locale("chs"));
        wcout << w;
    }catch(exception e)
    {
        cout << "error: " << e.what();
    }
}

 2014-06-07 00:22:26

boost读取utf-8编码xml文件,布布扣,bubuko.com

原文:http://www.cnblogs.com/hauter/p/3773246.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!