![](/img/trans.png)
[英]std::isalpha throws bad_cast when using with boost::locale
[英]Why is std::bad_cast thrown by boost::locale?
我试着理解如何使用boost :: locale来比较忽略大小写和变体的字符串。 我直接尝试了Boost文档中的代码:
http://www.boost.org/doc/libs/1_51_0/libs/locale/doc/html/collation.html
boost::locale::generator gen;
std::locale vLocale = gen("");
std::wstring a=L"Façade", b=L"facade";
// Following will throw bad_cast
bool eq = std::use_facet<boost::locale::collator<wchar_t>>(vLocale).compare(
boost::locale::collator_base::secondary,
a,
b
) == 0;
if(eq) std::cout << "OK" << std::endl;
此代码在运行时将抛出std :: bad_cast异常。 我在boost :: locale :: generator的构造函数中尝试了很多参数。 有谁知道我遇到的问题?
我正在使用带有g ++ 4.6和Boost 1.51.0的C ++ 11
您似乎使用了不正确的区域设置对象。您应该首先使用全局区域设置然后(如果要使用cout)将区域设置灌输到流。 像这样的Somethig:
boost::locale::generator gen;
std::locale loc = gen("");
std::locale::global(loc);
但是在您的示例中,如果您不使用cout,则只需设置全局区域设置,以便您需要使用构面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.