在boost :: Program_Options,如何为wstring的设置默认值? [英] In Boost::Program_Options, how to set default value for wstring?

查看:342
本文介绍了在boost :: Program_Options,如何为wstring的设置默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面code没有工作:

  wstring的CONFIG_FILE;
//声明一组,这将是选项
//只允许在命令行
PO :: options_description通用(通用选项);
generic.add_options()
    (帮助H,生产帮助信息)
    (配置,C,婆:: wvalue&所述; wstring的>(&放大器; CONFIG_FILE) - >中。一个配置的一个文件的名称DEFAULT_VALUE(LDXDrv.cfg))
    ;

编译失败,错误:


  

D:\\回购\\ a4x_ext \\ minidxdriver \\ testapp \\ configparser \\提升\\ lexical_cast.hpp(1096):错误C2039:'SETG :是不是成员'的boost ::详细:: lexical_stream_limited_src<图表,基地,性状及GT;



解决方案

啰嗦的解释:这是因为底层 typed_value 键入 program_options 试图在制定<$ C $办从 WCHAR 词法投地字符 C> m_default_value_as_text 私有成​​员。无论出于何种原因,basic_string的类型没有必要的功能来创建正确的模板类型。

幸运的是,typed_value类有DEFAULT_VALUE和implicit_value它提供了一个重新的字符串值presentation第二个覆盖。这绕过lexical_cast的,它解决了这个问题。是这样的:

  tvalue&LT; tstring&GT;() - &GT; DEFAULT_VALUE(_T(output.png),output.png)

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

The compilation failed with error:

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>'

解决方案

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

这篇关于在boost :: Program_Options,如何为wstring的设置默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆