Code below uses po::bool_switch(&flag)
in hope of automatically assigning the correct value to flag
.
My compile command is clang++ -std=c++11 test.cpp -o test -lboost_program_options
So I run the program with ./test -h
which shows no help message.
Why so?
#include <iostream>
#include <boost/program_options.hpp>
namespace
{
namespace po = boost::program_options;
}
int main(int ac, char ** av)
{
bool flag;
po::options_description help("Help options");
help.add_options()
( "help,h"
, po::bool_switch(&flag)->default_value(false)
, "produce this help message" );
po::variables_map vm;
po::parsed_options parsed
= po::parse_command_line(ac,av,help);
po::store(po::parse_command_line(ac,av,help),vm);
if (flag)
{
std::cout << help;
}
po::notify(vm);
return 0;
}