Boost logo

Boost Users :

Subject: [Boost-users] [program_options] vector parameters not working.
From: aiooua (aiooua_at_[hidden])
Date: 2009-09-21 10:04:32


hello,

I recently picked up boost to make use of the various libraries it
includes. Unfortunately, I got stuck with the very first one
(program_options) I used in my code. Any help would be appreciated
very much.

I want an option "bunch" which goes along with a bunch of numbers. I
thought the following code would do the job:

---------------------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <vector>
#include <boost/program_options.hpp>

using namespace std;
namespace po = boost::program_options;

int main(int argc, char* argv[])
{
  try
    {
      vector<int> numbers;
      po::options_description params("parameters");
      po::variables_map options;
      params.add_options()
        ("bunch,b", po::value< vector<int> >(&numbers), "a bunch of numbers");
      po::store(po::parse_command_line(argc, argv, params), options);
      po::notify(options);
      if(options.count("bunch")!=0)
        {
          copy (numbers.begin(), numbers.end(),
std::ostream_iterator<int>(cout, "\n"));
        }
    }
  catch(exception & e)
    {
      cerr << e.what() << endl;
    }
  return 0;
};
---------------------------------------------------------------------------------------

However, it doesn't seem to work as it should. When I run this as follows:

---------------------------------------------------------------------------------------
> test --bunch 4 2 42
4
---------------------------------------------------------------------------------------

It is just printing the first value - Am I doing something wrong here?
I'm using 'boost_1_40_0' which I compiled using MS Visual Studio 2005.

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