Boost C++ Libraries: Ticket #1645: Invalid unicode support for default_value https://svn.boost.org/trac10/ticket/1645 <p> The following example could not be compiled: ================================================================= </p> <p> #include &lt;string&gt; #include &lt;boost/program_options.hpp&gt; </p> <p> namespace po = boost::program_options; </p> <p> int main() { </p> <blockquote> <p> std::wstring test; po::options_description desc("Allowed options"); desc.add_options() </p> <blockquote> <p> ("test", po::wvalue&lt;std::wstring&gt;(&amp;test)-&gt;default_value(L"value"), "description"); </p> </blockquote> </blockquote> <p> } </p> <p> ================================================================= </p> <p> It is due to wvalue::default_value tries to do lexical_cast&lt;std::string&gt;(std::wstring). Also I cannot change default_value to default_value("value") as soon as it accepts only something convertible to std::wstring. In other words it is impossible to specify default_value for wstring option. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1645 Trac 1.4.3 Sascha Ochsenknecht <s.ochsenknecht@…> Thu, 12 Nov 2009 12:14:57 GMT cc set https://svn.boost.org/trac10/ticket/1645#comment:1 https://svn.boost.org/trac10/ticket/1645#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">s.ochsenknecht@…</span> added </li> </ul> <p> This problem appears for every value type which makes problem with lexical_cast&lt;std::string&gt;(). </p> <p> Here is a workaround: There as an overloaded version of default_value() which can be used to define the string representation of the default value: </p> <pre class="wiki">("test", po::value&lt;std::wstring&gt;()-&gt;default_value(L"value", "value"), "description.") </pre><p> This string (second parameter of default_value()) is then used for the help output. I would recommend to use this approach. </p> <p> Please comment. </p> Ticket Vladimir Prus Wed, 18 Nov 2009 13:05:46 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1645#comment:2 https://svn.boost.org/trac10/ticket/1645#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> I agree that explicitly specifying the textual rendition of default value is the best approach for now. </p> Ticket