简体   繁体   English

用于字符串编码的boost :: locale to_utf函数,喜欢抛出

[英]boost::locale to_utf function for string encoding, likes to throw

I'm having trouble using boost to convert between different string encoding. 我在使用boost来转换不同的字符串编码时遇到了麻烦。 After reading this , I tried doing this: 读完之后 ,我试着这样做:

boost::locale::generator gen;
std::locale loc = gen.generate("");// encoding local to the computer.
//std::locale loc = gen.generate("en_US.UTF-8"); // tried this too
//std::locale loc = gen.generate("en_US.UTF-8"); //doesn't work either
std::string someString = "test me";
std::string output = boost::locale::conv::to_utf<char>(someString, loc);

But it always fails with a std::bad_cast when it tries use_facet() inside to_utf. 但是当它在to_utf中尝试use_facet()时,它始终会失败并使用std :: bad_cast。

This would suggest that the boost locale::info facet isn't available for the locale being generated. 这表明boost locale :: info facet不适用于正在生成的语言环境。 But I tried a few different generations with no luck, and I expect the system default to always work, so I must be doing something wrong else where. 但我尝试了几代不同运气,我希望系统默认始终有效,所以我必须做错其他的地方。

Any ideas? 有任何想法吗?

std::locale loc("");
std::locale conv_loc = boost::locale::util::create_info(loc, loc.name());
std::string output = boost::locale::conv::to_utf<char>(someString, conv_loc);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM