Hi,
I'm having a problem with boost::program_options. I attached a
stripped-down version of the code that demonstrates the problem. I
have a number of positional arguments ( "ops" ), and one normal
argument ( "input-file,i" ).
Now, if i run the program
./op_test pos0 pos1 pos2 -i non_positional
it interpretes the "non_positional" as further positional arg, and
not as parameter belonging to -i.
Any hints on how to solve this are greatly appreciated.
My machine:
Mac OS X 10.4 ppc ( G5 )
XCode 2.4.1 ( gcc 4.0.1 )
boost 1.34
Greetings,
Jonas
The code:
// ------------------------ options.h -------------------
#ifndef __VMML__OPTIONS__H__
#define __VMML__OPTIONS__H__
#include
composing(), "specify operators " ) ; _positional_desc.add( "ops", -1 ); }
void options::setup( int argc, char* argv[] ) { _all_options.add( _generic_options ); boost_po::store( boost_po::command_line_parser( argc, argv ) .options( _all_options ) .positional( _positional_desc ) //.allow_unregistered() .run(), _options_map ); boost_po::notify( _options_map ); } void options::get_operator_chain( std::vector< std::string >& op_chain ) { if ( _options_map.count("ops") ) { const std::vector< std::string >& ops = _options_map["ops"].as< std::vector< std::string > >(); op_chain = ops; } } }//namespace vmml int main( int argc, char** argv ) { vmml::options opt; opt.setup( argc, argv ); std::vector< std::string > ops; opt.get_operator_chain( ops ); std::vector< std::string >::iterator it = ops.begin(); std::vector< std::string >::iterator itend = ops.end(); for( ; it != itend; ++it ) { std::cout << *it << std::endl; } }