使用 boost::options 而不给出参数值

Using boost::options without giving argument value

我想要 运行 程序使用 boost::program_option 而不给出值(仅标记)。 像那样(这里有一些其他的标志):

./main.x -b -f test.txt -r 26

现在你必须写:

./main.x -b 1 -f test.txt -r 26

关键字是 (-b)。我不想写1.

样本:

// boost fields
boost::program_options::variables_map fMap;
boost::program_options::options_description fOptions;

// Add some options to fOptions
fOptions.add_options()
("progressBar,b", po::value<int>(), "Progress bar.");
// some other options

boost::program_options::store(po::parse_command_line(argc, argv, fOptions), fMap);

if(fMap.count("progressBar"))
{
  int l_progressBar = fMap["progressBar"].as<int>();
  if(l_progressBar == 1)
  {
    // some staff
  }
}

//I would like to have something like that:
fOptions.add_options()
("progressBar,b", po::value<void>(), "Progress bar.");

if(fMap.count("progressBar"))
{
  // check if flag (-b) was set and do some staff
}

两个参数 operator() 应该可以解决问题:

fOptions.add_options()
("progressBar,b", "Progress bar.");