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

后端 未结 1 1800
梦毁少年i
梦毁少年i 2021-02-20 14:43

My code below did not work:

wstring config_file;
// Declare a group of options that will be 
// allowed only on command line
po::options_description generic(\"Ge         


        
相关标签:
1条回答
  • 2021-02-20 15:20

    Long-winded explanation: This is because the underlying typed_value type in program_options tries to do a lexical cast from wchar to char in setting the m_default_value_as_text private member. For whatever reason, the basic_string type does not have the necessary functions to create the correct template types.

    Luckily, the typed_value class has a second override for default_value and implicit_value which provides a string representation of the value. This bypasses the lexical_cast, which fixes the problem. Something like:

         tvalue< tstring >()->default_value( _T( "output.png" ), "output.png" )
    
    0 讨论(0)
提交回复
热议问题