20

I'm using boost::program_options in my program. I want to make a certain flag mandatory. Is is possible to do this with program_options in a way that it'll enforce this itself? i.e., throw an error message?

Amir Rachum
  • 76,817
  • 74
  • 166
  • 248

1 Answers1

21

According to the documentation you can specify that an option is required in the option description:

options_description desc;
desc.add_options()
    ("help", "produce help")
    ("count", value<int>()->required(), "number of executions")
    ;
sth
  • 222,467
  • 53
  • 283
  • 367
  • 3
    Be warned that there are still many older installations of boost that don't support this. The required() feature was added in 1.42. https://svn.boost.org/trac/boost/ticket/2982 – leecbaker Jan 08 '13 at 16:47
  • The output doen't really flag that its a required parameter. How to reflect that? – BTR Naidu Sep 02 '16 at 10:22