boost读取utf-8编码xml文件

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

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

代码如下

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

posted @ 2014-06-06 19:44  hauter  阅读(1276)  评论(0编辑  收藏  举报