在Boost::Program_Options中,如何设置wstring的默认值
In Boost::Program_Options, how to set default value for wstring?
下面的代码不起作用:
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(:错误C2039:
'setg'
:不是'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" )
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 在C++/Linux中设置单调时钟的一些技巧
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 嵌套在类中时无法设置成员数据
- 需要帮助设置在C++中使用的Potrace
- Ctypes wstring通过引用传递
- 如何在自删除后将对象设置为nullptr
- 将指针设置为"nullptr"并不能防止双重删除?
- 如何在Ubuntu中使用cmake设置qt4
- ld:bind_at_load和-bitcode_bundle(Xcode设置ENABLE_bitcode=YES)不能
- 如何在boost beast http请求中设置http头
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- 如何将这个C++哈希表转换为动态扩展和收缩,而不是使用硬设置的最大值
- 为什么文件名被设置为一个点,而不是在读取矢量中的文件名时
- 如何在24位SDL_Surface上设置像素的颜色
- std::设置自定义比较器
- 将字符串转换为wstring[不带区域设置的俄语符号::global]
- 在Boost::Program_Options中,如何设置wstring的默认值
- 根据MSVC++中的unicode设置,在std::string和std::wstring之间自动切换
- wstring支持什么区域设置