【发布时间】:2012-10-19 06:47:19
【问题描述】:
我试图了解如何使用 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
【问题讨论】:
-
作为一个提示,
bad_castexception 表示给定的locale没有请求的facet。
标签: c++ exception boost locale