2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
9 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 filetype=cpp.doxygen
11 \page faq Frequently Asked Questions
13 - \anchor faq_bad_cast <b>I try to use some Boost.Locale functions and I get an \c std::bad_cast exception thrown?</b>
16 \b Answer: You probably try to use incorrect \c std::locale object. All Boost.Locale tools relay on \c std::locale object's facets.
17 The locale object should be generated with \ref boost::locale::generator "generator" class and then passed to
18 the function or alternatively global locale should be set using \c std::locale::global() function such that
19 global locale (and default created one) would have required facets to use.
20 - \anchor faq_number <b>I had installed global locale and try to write something to stream but still get wrong output?</b>
23 #include <boost/locale.hpp>
27 boost::locale::generator gen;
28 std::locale::global(gen(""));
29 std::cout << boost::locale::as::date << std::time(0) << std::endl;
32 Prints a number instead of a date.
34 \b Answer: You forget to imbue the locale to the stream. Changing the global locale does not affect the
35 locale in existing \c iostream objects. Thus because \c std::out and other global streams were created
36 before changing the global locale Boost.Locale manipulators have no effect. You need to write:
38 #include <boost/locale.hpp>
42 boost::locale::generator gen;
43 std::locale l = gen("");
44 std::locale::global(l);
46 std::cout << boost::locale::as::date << std::time(0) << std::endl;