預設值
可以輕鬆指定預設值命令列引數:
// 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 Knight"), "Your rank");
它的值也被新增到變數 map:
std::cout << "Hello " << vm["name"].as<std::string>() << " " << vm["rank"].as<std::string>() << std::endl;
預設值顯示在說明中…
$ ./a.out
Error: the option '--name' is required but missing
Allowed Options:
--name arg Type your name to be greeted!
--rank arg (=Dark Knight) Your rank
…如果沒有指定則使用…
$ ./a.out --name Batman
Hello Batman Dark Knight
…但可以在命令列覆蓋:
$ ./a.out --name Batman --rank FlyingSquirrel
Hello Batman FlyingSquirrel