Boost logo

Boost Users :

From: Mikko Vainio (mivainio_at_[hidden])
Date: 2007-11-06 12:03:10


Here's an example:

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

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

int main( int argc, char* argv[] )
{
     vector< string > input_files;
     string myoption;
     po::options_description optdesc("Options");
     optdesc.add_options()
         ("input-file,i", po::value< vector< string > >(&input_files),
             "Input file name." )
         ("myoption", po::value< string >( &myoption ),
             "My option explained.")
     ;
     po::positional_options_description posopt;
     posopt.add("input-file", 3);
     po::variables_map varmap;
     po::store(po::command_line_parser(argc,
argv).options(optdesc).positional(posopt).run(), varmap);
     po::notify( varmap );
     if( varmap.count("myoption") )
         cout << "myoption = " << myoption << endl;
     cout << "\nInput was:\n";
     for( vector< string >::iterator si = input_files.begin(); si !=
input_files.end(); ++si )
         cout << *si << "\n";
     cout << endl;
     return 0;
}

/Mikko

swapna wrote:
> Thanks for yourresponse
> yes I have seen but wanted more help on it
>
>
> */Hartmut Kaiser <hartmut.kaiser_at_[hidden]>/* wrote:
>
>
> > Can Anyone suggest how to use commandline options with boost.
> > My requirement is: tool.exe -a "Parameter1" Parameter2
> > parameter I would run tool.exe with 3 parameters. also i have
> > many commandline options.
> > Can anyone please help me in assisting how to use boost
> > library for this.
>
> Have you seen the Boost.ProgramOptions library here:
> http://www.boost.org/doc/html/program_options.html?
>
> Regards Hartmut
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> ------------------------------------------------------------------------
> Chat on a cool, new interface. No download required. Click here.
> <http://in.rd.yahoo.com/tagline_webmessenger_10/*http://in.messenger.yahoo.com/webmessengerpromo.php>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users

-- 
:: Mikko Vainio <mikko.vainio_at_[hidden]> tel + 358 2 215 4600
:: Structural Bioinformatics Laboratory
:: Department of Biochemistry and Pharmacy
:: Abo Akademi University, Tykistokatu 6A, FI-20520 Turku Finland

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