c – 用于字符串编码的boost :: locale to_utf函数,喜欢抛出
发布时间:2020-12-16 07:00:21 所属栏目:百科 来源:网络整理
导读:我在使用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
我在使用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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |