In Boost :: Program_Options, how to set the default value for wstring?

My code below does not work:

wstring config_file;
// Declare a group of options that will be 
// allowed only on command line
po::options_description generic("Generic options");
generic.add_options()
    ("help,h", "produce help message")
    ("config,c", po::wvalue<wstring>(&config_file)->default_value(L"DXDrv.cfg"), "name of a file of a configuration.")
    ;

Compilation error with error:

d: \ repo \ a4x_ext \ minidxdriver \ testapp \ configparser \ boost \ lexical_cast.hpp (1096): error C2039:: 'setg'is not a member'boost::detail::lexical_stream_limited_src<CharT,Base,Traits>'

+5
source share
1 answer

Long term explanation. This is due to the fact that the base type typed_valuein program_optionstries to make a lexical translation from wcharto charwhen setting up a private member m_default_value_as_text. For some reason, the basic_string type does not have the necessary functions to create the correct template types.

, typed_value default_value implicit_value, . lexical_cast, . - :

     tvalue< tstring >()->default_value( _T( "output.png" ), "output.png" )
+10

All Articles