跳过未知选项,而不使用boost程序选项 [英] skipping unknown options without throwing with boost program options

查看:206
本文介绍了跳过未知选项,而不使用boost程序选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这些天我在使用Boost程序选项来读取INI文件。

These days I am playing with Boost program options for reading INI files.

我在代码中抛出一个异常,文件中有一行未知选项。
你知道是否可能,以及如何让下面的代码读取整个文件?我想跳过未知的选项不抛出,所以我可以读取所有可能的值。
感谢很多
AFG

The code I have throws an exception once in the file there is a line with an unknown option. Do you know whether is possible and how to let the code below read the whole file? I want to skip the unknown options without throwing so that I can read all possible values. Thanks a lot AFG

 namespace pod = boost::program_options;
 pod::options_description options("Options");
 std::string myArgValue;
 options.add_options()     

      ("SECT_A.Option_A", 
           pod::value<int>()->default_value(1), 
           "xxx")

      ("SECT_B.Option_B", 
           pod::value<std::string>(&myArgValue),
           "xxx")
 ;

 pod::variables_map vm;
 pod::store( pod::parse_config_file( s, options ) , vm);
 pod::notify( vm );


推荐答案

Yip: allow_unregistered ,请查看:

http://www.boost.org/doc/libs/1_45_0/doc/html/program_options/howto.html#id2075177

这篇关于跳过未知选项,而不使用boost程序选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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