c++ - boost program_options accept all values after last flag -
Is there a way to gather all values after a specified argument with boost :: program_options? Although there are two precautions I need to take care of, I need to accept unrecognized arguments, and I have to accept the values in which the dash can happen I have tried to play with command_line_parar vs. parse_command_line and I either Can get unrecognized or value in which the dash is, but not both.
Example: ./myprog Ignore1 Ignore2 - Accept 1 - Highly Accepted 2 - Accept all 1 2 -3 4
Verifying this to me is really no difference - All approved final flags have been passed; I'm just looking for logic that gives the strings vector for everything after that flag.
tried?
#include & lt; Boost / program_options.hpp & gt; # Include & lt; Boost / foreach.hpp & gt; # Include & lt; Iostream & gt; #include & lt; String & gt; Name space po = boost :: program_options; Int main (unsigned int argc, char ** argv) {std :: string foo; Std :: vector & lt; Std :: string & gt; Apart from; Po :: options_description desc; Des.add_options () ("foo", po :: value & lt; std :: string & gt; (& amp; foo), "some string") ("additional option", po :: value (and additional) , "Spare parts"); Po :: positional_options_description p; P.add ("Additional Options", -1); Po :: variables_map vm; Po :: store (po :: command_line_parser (argc, argv). Options (desc). Positional (p). Run (), vm); Po :: Notify (VM); BOOST_FOREACH (const std :: string & amp; i additional) {std :: cout & lt; & Lt; I & lt; & Lt; Std :: endl; } Return 0; }
Sample Sessions
samm @ macmini ~ & gt; ./a.out --foo times far away hello world how far are you hello world how are you samm @ macmini ~ & gt;
Comments
Post a Comment