[英]Compiles but getting 'uncaught exception of type std::bad_cast'
我正在尝试使用Boost for C ++。 这是一个用g++ -Wall test.cpp /usr/local/Cellar/boost/1.55.0/lib/libboost_locale-mt.a
编译的小程序g++ -Wall test.cpp /usr/local/Cellar/boost/1.55.0/lib/libboost_locale-mt.a
。
但是,当我运行它时,这是我得到的错误: libc++abi.dylib: terminating with uncaught exception of type std::bad_cast: std::bad_cast Abort trap: 6
#include <string>
#include <iostream>
#include <boost/locale.hpp>
int main(void) {
char test[] = "Variété";
boost::locale::to_upper(test);
std::cout << test << std::endl;
return 0;
}
这可能是什么原因? 谢谢!
我在Mac OSX Mavericks上。
根据文档:
std::basic_string<CharType> boost::locale::to_lower(CharType const *str,
std::locale const &loc = std::locale())
根据区域设置将NUL终止的字符串str转换为小写
注意: 如果loc没有安装转换器方面,则抛出std :: bad_cast
因此,这解决了我机器上的问题。
#include <string>
#include <iostream>
#include <boost/locale.hpp>
int main(void) {
std::string test = "Variété";
std::locale loc = boost::locale::generator().generate("en_US.UTF-8");
std::string test_u = boost::locale::to_upper(test, loc);
std::cout << test << " -> " << test_u << std::endl;
return 0;
}
输出:
Variété -> VARIÉTÉ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.