|
Boost Users : |
Subject: [Boost-users] default value of program options
From: Axel (axel.boost_at_[hidden])
Date: 2009-12-02 05:48:58
Hi
I m using program options classes to handles command line arguments
(Boost version 1.35, Debian lenny packages). I don't manage to get this
code work :
boost::program_options::options_description cmd_line_options_("Command
line options") ;
boost::program_options::variables_map current_options_ ;
int port_ = 0 ;
cmd_line_options_.add_options() ("port,p",
boost::program_options::value<int>(&port_), "specify the destination
port to use") ;
try
{
boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(cmd_line_options_).run(), current_options_) ;
}
catch(po::error &e)
{
cout << "Error when parsing command line arguments: " << e.what() <<
"\n" ;
}
cout << port_ << ":" << current_options_["port"].as<int>() << endl ;
When executing : ./foo --port=12345, the output is :
0:12345
The port_ variable value remains to be 0 when the current_options_
variable hold the right value (12345).
Could someone tell me what am I doing wrong ?
Thanks
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