3rdParty/boost/1.78.0/libs/locale/doc/html/faq.html
| | Boost.Locale |
Frequently Asked Questions
std::bad_cast exception thrown?Answer: You probably try to use incorrect std::locale object. All Boost.Locale tools relay on std::locale object's facets. The locale object should be generated with generator class and then passed to the function or alternatively global locale should be set using std::locale::global() function such that global locale (and default created one) would have required facets to use.
#include <boost/locale.hpp>
#include <iostream>
int main()
{
std::locale::global(gen(""));
std::cout << boost::locale::as::date << std::time(0) << std::endl;
}
Prints a number instead of a date.
Answer: You forget to imbue the locale to the stream. Changing the global locale does not affect the locale in existing iostream objects. Thus because std::out and other global streams were created before changing the global locale Boost.Locale manipulators have no effect. You need to write:
#include <boost/locale.hpp>
#include <iostream>
int main()
{
std::locale l = gen("");
std::locale::global(l);
std::cout.imbue(l);
std::cout << boost::locale::as::date << std::time(0) << std::endl;
}