Boost logo

Boost Users :

Subject: [Boost-users] [program_options] How to extract option value?
From: Krzysztof (kj_at_[hidden])
Date: 2011-05-03 16:30:37


In order to get the option value I have this code:

options_description opd;
string in;

opd.add_options()
  ("help","Display help")
  ("input_file,I",value<string>(),"Input file with group division");

variables_map vm;

store(parse_command_line(argc,argv,opd),vm);
notify(vm);

if(!vm["help"].empty())
   cout<<opd<<'\n';
else
   in = vm["input_file"].as<string>();

However the last line issues this exception:

terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_any_cast>
>'
   what(): boost::bad_any_cast: failed conversion using boost::any_cast

What do I wrong?

-- 
Regards
Krzysztof J.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net