Boost logo

Boost Users :

Subject: Re: [Boost-users] default value of program options
From: Axel (axel.boost_at_[hidden])
Date: 2009-12-02 08:57:00


  You were right. So obvious that I saw nothing.

Thanks for your help

On 02/12/2009 14:00, Diederick C. Niehorster wrote:
> After you run store, you also need to call notify(); think that should
> do the trick.
>
> Best,
> Dee
>
> On Wed, Dec 2, 2009 at 6:48 PM, Axel<axel.boost_at_[hidden]> wrote:
>> 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 mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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