2013-11-03 56 views
2

在Win 7 64bits和VS2010上升级1.54 x64。编译为“64版”,并运行下面的代码:boost :: locale :: to_lower throw bad_cast exception

#include <boost/locale/conversion.hpp> 
std::wstring y = L"NoNseNSE"; 
std::wstring w = boost::locale::to_lower(y); 

抛出std::bad_cast例外。即使没有添加之后改变(如在别处所建议的):

std::locale mylocale(""); 
std::locale::global(mylocale); 

或改变to_lower(y)到:to_lower(y, mylocale)或使用std::string代替std::wstring或在环境设置LANG。

目标是转换为小写的意大利语UTF-8单词。我没有发现这样的问题,所以我认为这是我的机器特定问题或增强库问题。顺便说一下,我已经从sourceforge下载了预编译的boost库(boost_1_54_0-msvc-10.0-64.exe)。任何想法? 谢谢!当您的区域传递到boost::locale::to_lower 马里奥

+0

如果使用utf8,则根据定义,'wstring'似乎不存在问题 – sehe

回答

4

,抛出此异常(默认情况下std::locale(),即全局区域的副本)没有安装boost::locale::converter方面。 See this for the related documentation.

改为使用boost::locale::generator来创建区域设置。 (另请参阅文档链接的示例,例如this one。)

+0

谢谢,现在可以使用。我错误地认为'std :: locale lx;'和'boost :: locale :: generator gen; std :: locale lx = gen(“”);'是等价的。 – SiliconValley

相关问题