0
我試圖做兩個std :: u16string實例與boost,不區分大小寫的字符串比較。基於我的搜索,我需要生成一個語言環境,我正在做。與std :: u16string一起使用boost :: iequals
#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
我在做什麼錯?