使用-lboost_locale编译的以下简单代码会生成错误的强制转换异常。它与boost教程本身的代码相同。有什么帮助吗?
#include <boost/locale.hpp>
#include <iostream>
int main()
{
using namespace boost::locale;
date_time now;
std::cout<<as::date<<now<<std::endl;
}
答案 0 :(得分:3)
你需要灌输(全局)语言环境:
<强> Live On Coliru 强>
#include <boost/locale.hpp>
#include <iostream>
int main() {
using namespace boost::locale;
boost::locale::generator gen;
std::locale loc = gen.generate(""); // or "C", "en_US.UTF-8" etc.
std::locale::global(loc);
std::cout.imbue(loc);
date_time_period_set things;
date_time now;
std::cout << as::date << now << std::endl;
}
打印,例如在coliru:
09/17/15