我正在尝试将一些字符串从ASCII转换为UTF8。
我搜了很多东西,但找不到。
所以我对此进行了编码。
std::string ASCII("ASCII string");
auto utf8 = boost::locale::conv::to_utf<char>(ansi, std::locale("en_US.UTF8"));是这样的吗?在我的系统里这是行不通的。
求你帮帮我。
谢谢。
发布于 2014-08-15 08:51:55
如果您的意思是将系统区域设置转换为utf8,反之亦然,那么我们将使用以下操作非常好:
static std::string fromLocale(const std::string &localeStr){
boost::locale::generator g;
g.locale_cache_enabled(true);
std::locale loc = g(boost::locale::util::get_system_locale());
return boost::locale::conv::to_utf<char>(localeStr,loc);
}
static std::string toLocale(const std::string &utf8Str){
boost::locale::generator g;
g.locale_cache_enabled(true);
std::locale loc = g(boost::locale::util::get_system_locale());
return boost::locale::conv::from_utf<char>(utf8Str,loc);
}https://stackoverflow.com/questions/25311345
复制相似问题