boost Boost Program Options Switches


Example

A switch is a command line argument which takes no value. It can be specified with:

desc.add_options()
  ("hidden", po::bool_switch()->default_value(false), "Hide your name");

And used with:

if (vm["hidden"].as<bool>())
   std::cout << "Hello *****" << std::endl;

from the command line:

 $ ./a.out --name Batman --hidden
Hello *****

and in the description it shows as:

Allowed Options:
  --name arg                Type your name to be greeted!
  --rank arg (=Dark Knight) Your rank
  --hidden                  Hide your name