|
Boost Users : |
From: Jeremy Conlin (jeremit0_at_[hidden])
Date: 2008-03-11 16:53:29
I am using program_options and want to write to the screen the options and
their values. This allows me to verify everything is working properly
before I execute a long running command. I thought I could just iterate
over the map and print out each option, but that requires casting the option
to a specific variable which must be known a priori. This is what I have
right now
cout << "options:\n";
po::variables_map::iterator optIter = options.begin();
for( ; optIter != options.end(); ++optIter ){
cout << "\t" << optIter->first << " = " << optIter->second.as<string>()
<< std::endl;
}
When my option isn't a string (e.g. bool or int) then I get the error:
terminate called after throwing an instance of 'boost::bad_any_cast'
what(): boost::bad_any_cast: failed conversion using boost::any_cast
Can someone show me how to do this?
Thanks,
Jeremy
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