boost Boost Program Options Switches

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any boost Question?