Boost logo

Boost :

From: Neal D. Becker (ndbecker2_at_[hidden])
Date: 2004-03-25 14:50:18


So far I see examples where the result of using program_options parsers is
to store something into a variable map.

Is it possible to directly store results into variables? For example,
assume:

int main (int argc, char** argv) {
  double value = 10.;

  mythical_parser (...);

};

How do I use program_options to set "value"? Any examples?

So far the only way I know is:

  po::options_description desc("Allowed options");
  desc.add_options()
    ("help", "produce help message")
    ("value", po::value<int>())
   ;

  po::variables_map vm;

  po::store(po::parse_command_line(argc, argv, desc), vm);
  po::notify(vm);
  if (vm.count("value"))
    value = vm["value"].as<int>();


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk