C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – 用于字符串编码的boost :: locale to_utf函数,喜欢抛出大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我在使用boost来转换不同的字符串编码时遇到了麻烦.
After reading 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);

但是当它在to_utf中尝试use_faCET()时,它始终会失败并使用std :: bad_cast.

这将表明正在生成的语言环境的boost locale :: info facet isn’t available.但我尝试了几代不同运气,我希望系统认始终有效,所以我必须做错其他的地方.

有任何想法吗?

解决方法

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);

大佬总结

以上是大佬教程为你收集整理的c – 用于字符串编码的boost :: locale to_utf函数,喜欢抛出全部内容,希望文章能够帮你解决c – 用于字符串编码的boost :: locale to_utf函数,喜欢抛出所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。