3

The following simple code, compiled with -lboost_locale generates a bad cast exception. It is the same code in the boost tutorial itself. Any help?

#include <boost/locale.hpp>
#include <iostream>
int main()
{
  using namespace boost::locale;
  date_time now;
  std::cout<<as::date<<now<<std::endl;
}
Alberto Contador
  • 263
  • 1
  • 13

1 Answers1

4

You need to imbue (global) locales:

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;
}

Prints, e.g. on coliru:

09/17/15
sehe
  • 374,641
  • 47
  • 450
  • 633