11

我下面的代码不起作用:

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.")
    ;

编译失败并出现错误:

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

4

1 回答 1

16

冗长的解释:这是因为底层typed_value类型 inprogram_options试图在设置私有成员时进行词法转换 from wcharto 。无论出于何种原因,basic_string 类型都没有创建正确模板类型所需的功能。charm_default_value_as_text

幸运的是,typed_value 类对 default_value 和implicit_value 有第二个覆盖,它提供了值的字符串表示。这绕过了 lexical_cast,从而解决了问题。就像是:

     tvalue< tstring >()->default_value( _T( "output.png" ), "output.png" )
于 2011-12-18T03:28:40.963 回答