On Mon, Sep 21, 2009 at 10:04 AM, aiooua
<aiooua@gmail.com> wrote:
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 mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users