加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 在Boost :: Program_Options中,如何设置wstring的默认值?

发布时间:2020-12-16 03:45:57 所属栏目:百科 来源:网络整理
导读:我的代码不起作用: wstring config_file;// Declare a group of options that will be // allowed only on command linepo::options_description generic("Generic options");generic.add_options() ("help,h","produce help message") ("config,c",po::wva
我的代码不起作用:
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:repoa4x_extminidxdrivertestappconfigparserboostlexical_cast.hpp(1096) : error C2039: 'setg' : is not a member of 'boost::detail::lexical_stream_limited_src<CharT,Base,Traits>'

解决方法

冗长的解释:这是因为program_options中的基础typed_value类型在设置m_default_value_as_text私有成员时尝试从wchar到char进行词法转换.无论出于何种原因,basic_string类型都没有必要的函数来创建正确的模板类型.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读