| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> |
| <meta http-equiv="X-UA-Compatible" content="IE=9"/> |
| <title>Boost.Locale: Frequently Asked Questions</title> |
| |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> |
| <link href="navtree.css" rel="stylesheet" type="text/css"/> |
| <script type="text/javascript" src="jquery.js"></script> |
| <script type="text/javascript" src="resize.js"></script> |
| <script type="text/javascript" src="navtree.js"></script> |
| <script type="text/javascript"> |
| $(document).ready(initResizable); |
| </script> |
| |
| |
| </head> |
| <body> |
| <div id="top"><!-- do not remove this div! --> |
| |
| |
| <div id="titlearea"> |
| <table cellspacing="0" cellpadding="0"> |
| <tbody> |
| <tr style="height: 56px;"> |
| |
| <td id="projectlogo"><img alt="Logo" src="boost-small.png"/></td> |
| |
| |
| <td style="padding-left: 0.5em;"> |
| <div id="projectname">Boost.Locale |
| |
| </div> |
| |
| </td> |
| |
| |
| |
| </tr> |
| </tbody> |
| </table> |
| </div> |
| |
| <!-- Generated by Doxygen 1.7.6.1 --> |
| <div id="navrow1" class="tabs"> |
| <ul class="tablist"> |
| <li><a href="index.html"><span>Main Page</span></a></li> |
| <li><a href="modules.html"><span>Modules</span></a></li> |
| <li><a href="namespaces.html"><span>Namespaces</span></a></li> |
| <li><a href="annotated.html"><span>Classes</span></a></li> |
| <li><a href="files.html"><span>Files</span></a></li> |
| <li><a href="examples.html"><span>Examples</span></a></li> |
| </ul> |
| </div> |
| </div> |
| <div id="side-nav" class="ui-resizable side-nav-resizable"> |
| <div id="nav-tree"> |
| <div id="nav-tree-contents"> |
| </div> |
| </div> |
| <div id="splitbar" style="-moz-user-select:none;" |
| class="ui-resizable-handle"> |
| </div> |
| </div> |
| <script type="text/javascript"> |
| initNavTree('faq.html',''); |
| </script> |
| <div id="doc-content"> |
| <div class="header"> |
| <div class="headertitle"> |
| <div class="title">Frequently Asked Questions </div> </div> |
| </div><!--header--> |
| <div class="contents"> |
| <div class="textblock"><ul> |
| <li><a class="anchor" id="faq_bad_cast"></a><b>I try to use some Boost.Locale functions and I get an <code>std::bad_cast</code> exception thrown?</b> <br/> |
| <br/> |
| <b>Answer:</b> You probably try to use incorrect <code>std::locale</code> object. All Boost.Locale tools relay on <code>std::locale</code> object's facets. The locale object should be generated with <a class="el" href="classboost_1_1locale_1_1generator.html">generator</a> class and then passed to the function or alternatively global locale should be set using <code>std::locale::global()</code> function such that global locale (and default created one) would have required facets to use.</li> |
| <li><a class="anchor" id="faq_number"></a><b>I had installed global locale and try to write something to stream but still get wrong output?</b> For example: <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <boost/locale.hpp></span> |
| <span class="preprocessor"> #include <iostream></span> |
| <span class="keywordtype">int</span> main() |
| { |
| <a class="code" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">boost::locale::generator</a> gen; |
| std::locale::global(gen(<span class="stringliteral">""</span>)); |
| std::cout << <a class="code" href="group__manipulators.html#gae05b82e6658dc573521518fed5f5c77f">boost::locale::as::date</a> << <a class="code" href="group__manipulators.html#gae669b101cbeaed6f6d246ebdcaa8f39c">std::time</a>(0) << std::endl; |
| } |
| </pre></div> Prints a number instead of a date. <br/> |
| <b>Answer:</b> You forget to imbue the locale to the stream. Changing the global locale does not affect the locale in existing <code>iostream</code> objects. Thus because <code>std::out</code> and other global streams were created before changing the global locale Boost.Locale manipulators have no effect. You need to write: <div class="fragment"><pre class="fragment"><span class="preprocessor"> #include <boost/locale.hpp></span> |
| <span class="preprocessor"> #include <iostream></span> |
| <span class="keywordtype">int</span> main() |
| { |
| <a class="code" href="classboost_1_1locale_1_1generator.html" title="the major class used for locale generation">boost::locale::generator</a> gen; |
| std::locale l = gen(<span class="stringliteral">""</span>); |
| std::locale::global(l); |
| std::cout.imbue(l); |
| std::cout << <a class="code" href="group__manipulators.html#gae05b82e6658dc573521518fed5f5c77f">boost::locale::as::date</a> << <a class="code" href="group__manipulators.html#gae669b101cbeaed6f6d246ebdcaa8f39c">std::time</a>(0) << std::endl; |
| } |
| </pre></div> </li> |
| </ul> |
| </div></div><!-- contents --> |
| </div> |
| <div id="nav-path" class="navpath"> |
| <ul> |
| <li class="navelem"><a class="el" href="index.html">Boost.Locale</a> </li> |
| <li class="navelem"><a class="el" href="appendix.html">Appendix</a> </li> |
| |
| <li class="footer"> |
| © Copyright 2009-2012 Artyom Beilis, Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License</a>, Version 1.0. |
| </li> |
| </ul> |
| </div> |
| |
| |
| </body> |
| </html> |