Tutorial by Examples

Boost program options provides a simple and safe way to parse and handle command line arguments. #include <boost/program_options.hpp> #include <string> #include <iostream> int main(int argc, char** argv) { namespace po = boost::program_options; po::variables_map vm; ...
boost::program_options::notify can be used to report any errors in the paramters passing #include <boost/program_options.hpp> #include <string> #include <iostream> int main(int argc, char** argv) { namespace po = boost::program_options; po::variables_map vm; po::op...
A default valued command line argument can be specified easily: // declare options desc.add_options() ("name", po::value<std::string>()->required(), "Type your name to be greeted!") ("rank", po::value<std::string>()->default_value("Dark Kn...
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 ...

Page 1 of 1