faq.txt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  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)
  7. //
  8. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 filetype=cpp.doxygen
  9. /*!
  10. \page faq Frequently Asked Questions
  11. - \anchor faq_bad_cast <b>I try to use some Boost.Locale functions and I get an \c std::bad_cast exception thrown?</b>
  12. \n
  13. \n
  14. \b Answer: You probably try to use incorrect \c std::locale object. All Boost.Locale tools relay on \c std::locale object's facets.
  15. The locale object should be generated with \ref boost::locale::generator "generator" class and then passed to
  16. the function or alternatively global locale should be set using \c std::locale::global() function such that
  17. global locale (and default created one) would have required facets to use.
  18. - \anchor faq_number <b>I had installed global locale and try to write something to stream but still get wrong output?</b>
  19. For example:
  20. \code
  21. #include <boost/locale.hpp>
  22. #include <iostream>
  23. int main()
  24. {
  25. boost::locale::generator gen;
  26. std::locale::global(gen(""));
  27. std::cout << boost::locale::as::date << std::time(0) << std::endl;
  28. }
  29. \endcode
  30. Prints a number instead of a date.
  31. \n
  32. \b Answer: You forget to imbue the locale to the stream. Changing the global locale does not affect the
  33. locale in existing \c iostream objects. Thus because \c std::out and other global streams were created
  34. before changing the global locale Boost.Locale manipulators have no effect. You need to write:
  35. \code
  36. #include <boost/locale.hpp>
  37. #include <iostream>
  38. int main()
  39. {
  40. boost::locale::generator gen;
  41. std::locale l = gen("");
  42. std::locale::global(l);
  43. std::cout.imbue(l);
  44. std::cout << boost::locale::as::date << std::time(0) << std::endl;
  45. }
  46. \endcode
  47. */