【发布时间】:2017-04-23 00:58:16
【问题描述】:
我正在尝试使用 boost 对两个 std::u16string 实例进行不区分大小写的字符串比较。根据我的搜索,我需要生成一个我正在做的语言环境。
#include <boost/algorithm/string.hpp>
#include <boost/locale.hpp>
#include <locale>
#include <iostream>
int main() {
// Create the strings
std::u16string str1 = boost::locale::conv::utf_to_utf<char16_t>("unicode");
std::u16string str2 = boost::locale::conv::utf_to_utf<char16_t>("UNICODE");
// Create the locale
boost::locale::generator gen;
std::locale loc = gen("");
// Doesn't matter if I do this or not
//std::locale::global(loc);
// Try to compare
if (boost::iequals(str1, str2, loc)) {
std::cout << "EQUAL\n";
} else {
std::cout << "!EQUAL\n";
}
return 0;
}
这会导致 std::bad_cast 异常:
terminate called after throwing an instance of 'std::bad_cast'
what(): std::bad_cast
我做错了什么?
【问题讨论】: