boost.locale 初用

来源:互联网 发布:linux vnc 安装 编辑:程序博客网 时间:2024/06/09 09:09
// boost编码转换// made by davidsu33#include "stdafx.h"#include <boost/locale.hpp>#include <string>using namespace std;//GBK 2 UTFwstring strToWstr(const string& str){return boost::locale::conv::to_utf<wchar_t>(str, "GBK");}//UTF 2 GBKstring wstrTostr(const wstring& wstr){return boost::locale::conv::from_utf(wstr, "GBK");}//Test boost::localevoid 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;}

0 0