boost program options - how to automatically store the value of a simple flag into a variable? -
the boost option parser allows 1 assign variable store option value, instead of using so_long["typing"].as<bool>()
way:
bool flag_value; entries.add_options() ("flag", value<bool>(&flag_value), "a simple flag value"); ...... cout<<"flag value is: "<<flag_value<<endl;
however, above option declaration not create simple flag option. requires enter value (--flag true|false|on|off|yes|no|1|0), not want.
so, there way store result inside boolean value, , still keep option simple flag?
to have option no value (passing means set true
) should create this:
options_description desc; desc.add_options() ("help", "produce message")
to use notifier such option can use following type semantics:
boost::program_options::bool_switch()
it can have true
or false
values , no value can explicitly taken option command line. if option passed value true
. if not passed - value false
.
Comments
Post a Comment