欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

转换UTF8与GBK编码的Boost Locale技巧

最编程 2024-01-12 20:51:46
...

前言

实现Windows和Linux跨平台编码转换


头文件

#include <boost/locale.hpp>


库文件引入

Windows下依赖libboost_locale-vc140-mt-gd-1_66.lib库文件

LInux下依赖libboost_locale.so.1.66.0


封装函数

std::string UTF8ToGBK(const std::string &strUTF8)
{
return boost::locale::conv::from_utf(strUTF8.c_str(), std::string("gb2312"));
}
std::string GBKToUTF8(const std::string &strGBK)
{
//string str = boost::locale::conv::between(strGBK, "gb2312", "UTF-8");
return boost::locale::conv::to_utf<char>(strGBK.c_str(), std::string("gb2312"));
}


推荐阅读