skipping unknown options without throwing with boost program options

戏子无情 提交于 2019-12-06 06:28:48

问题


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

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

回答1:


Yip: allow_unregistered(), have a look at:

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



来源:https://stackoverflow.com/questions/4459650/skipping-unknown-options-without-throwing-with-boost-program-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!