1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns=
"http://www.w3.org/1999/xhtml">
4 <meta http-equiv=
"Content-Type" content=
"text/xhtml;charset=UTF-8"/>
5 <meta http-equiv=
"X-UA-Compatible" content=
"IE=9"/>
6 <meta name=
"generator" content=
"Doxygen 1.8.6"/>
7 <title>Boost.Locale: Frequently Asked Questions
</title>
8 <link href=
"tabs.css" rel=
"stylesheet" type=
"text/css"/>
9 <script type=
"text/javascript" src=
"jquery.js"></script>
10 <script type=
"text/javascript" src=
"dynsections.js"></script>
11 <link href=
"navtree.css" rel=
"stylesheet" type=
"text/css"/>
12 <script type=
"text/javascript" src=
"resize.js"></script>
13 <script type=
"text/javascript" src=
"navtree.js"></script>
14 <script type=
"text/javascript">
15 $(document).ready(initResizable);
16 $(window).load(resizeHeight);
18 <link href=
"doxygen.css" rel=
"stylesheet" type=
"text/css" />
21 <div id=
"top"><!-- do not remove this div, it is closed by doxygen! -->
23 <table cellspacing=
"0" cellpadding=
"0">
25 <tr style=
"height: 56px;">
26 <td id=
"projectlogo"><img alt=
"Logo" src=
"boost-small.png"/></td>
27 <td style=
"padding-left: 0.5em;">
28 <div id=
"projectname">Boost.Locale
35 <!-- end header part -->
36 <!-- Generated by Doxygen 1.8.6 -->
37 <div id=
"navrow1" class=
"tabs">
39 <li><a href=
"index.html"><span>Main
 Page
</span></a></li>
40 <li class=
"current"><a href=
"pages.html"><span>Related
 Pages
</span></a></li>
41 <li><a href=
"modules.html"><span>Modules
</span></a></li>
42 <li><a href=
"namespaces.html"><span>Namespaces
</span></a></li>
43 <li><a href=
"annotated.html"><span>Classes
</span></a></li>
44 <li><a href=
"files.html"><span>Files
</span></a></li>
45 <li><a href=
"examples.html"><span>Examples
</span></a></li>
49 <div id=
"side-nav" class=
"ui-resizable side-nav-resizable">
51 <div id=
"nav-tree-contents">
52 <div id=
"nav-sync" class=
"sync"></div>
55 <div id=
"splitbar" style=
"-moz-user-select:none;"
56 class=
"ui-resizable-handle">
59 <script type=
"text/javascript">
60 $(document).ready(function(){initNavTree('faq.html','');});
62 <div id=
"doc-content">
64 <div class=
"headertitle">
65 <div class=
"title">Frequently Asked Questions
</div> </div>
67 <div class=
"contents">
68 <div class=
"textblock"><ul>
69 <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/>
71 <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>
72 <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"><div class=
"line"><span class=
"preprocessor">#include
<boost/locale.hpp
></span></div>
73 <div class=
"line"><span class=
"preprocessor">#include
<iostream
></span></div>
74 <div class=
"line"><span class=
"keywordtype">int
</span> main()
</div>
75 <div class=
"line">{
</div>
76 <div class=
"line"> <a class=
"code" href=
"classboost_1_1locale_1_1generator.html">boost::locale::generator
</a> gen;
</div>
77 <div class=
"line"> std::locale::global(gen(
<span class=
"stringliteral">""</span>));
</div>
78 <div class=
"line"> 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;
</div>
79 <div class=
"line">}
</div>
80 </div><!-- fragment --> Prints a number instead of a date.
<br/>
81 <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"><div class=
"line"><span class=
"preprocessor">#include
<boost/locale.hpp
></span></div>
82 <div class=
"line"><span class=
"preprocessor">#include
<iostream
></span></div>
83 <div class=
"line"><span class=
"keywordtype">int
</span> main()
</div>
84 <div class=
"line">{
</div>
85 <div class=
"line"> <a class=
"code" href=
"classboost_1_1locale_1_1generator.html">boost::locale::generator
</a> gen;
</div>
86 <div class=
"line"> std::locale l = gen(
<span class=
"stringliteral">""</span>);
</div>
87 <div class=
"line"> std::locale::global(l);
</div>
88 <div class=
"line"> std::cout.imbue(l);
</div>
89 <div class=
"line"> 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;
</div>
90 <div class=
"line">}
</div>
91 </div><!-- fragment --> </li>
93 </div></div><!-- contents -->
94 </div><!-- doc-content -->
97 © 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.