// boost编码转换
// made by davidsu33
#include "stdafx.h"
#include <boost/locale.hpp>
#include <string>
using namespace std;
//GBK 2 UTF
wstring strToWstr(const string& str)
{
return boost::locale::conv::to_utf<wchar_t>(str, "GBK");
}
//UTF 2 GBK
string wstrTostr(const wstring& wstr)
{
return boost::locale::conv::from_utf(wstr, "GBK");
}
//Test boost::locale
void test_locale()
{
wcout<<L"Test wchar:"<<endl;
wcout<<strToWstr("一个中热刚发的撒垃圾")<<endl;
cout<<"Test char:"<<endl;
cout<<wstrTostr(L"家乐福大家了范德萨发生地方")<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
//设置全局的C运行库locale 可针对iostream fstream等单独设置
std::locale::global(std::locale("")); //默认
test_locale();
getchar();
return 0;
}
boost.locale 初用
最新推荐文章于 2022-05-19 08:42:59 发布