码迷,mamicode.com
首页 > 其他好文 > 详细

boost读取utf-8编码xml文件

时间:2014-06-11 08:16:37      阅读:367      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   ext   

参照: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

boost读取utf-8编码xml文件

标签:style   class   blog   code   http   ext   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!