你试过位置选项吗?
#include <boost/program_options.hpp>
#include <boost/foreach.hpp>
#include <iostream>
#include <string>
namespace po = boost::program_options;
int
main( unsigned int argc, char** argv )
{
std::string foo;
std::vector<std::string> extra;
po::options_description desc;
desc.add_options()
("foo", po::value<std::string>(&foo), "some string")
("extra-options", po::value(&extra), "extra args" )
;
po::positional_options_description p;
p.add("extra-options", -1);
po::variables_map vm;
po::store(
po::command_line_parser(argc, argv).
options(desc).
positional(p).
run(),
vm);
po::notify(vm);
BOOST_FOREACH( const std::string& i, extra ) {
std::cout << i << std::endl;
}
return 0;
}
示例会话
samm@macmini ~> ./a.out --foo bar far hello world how are you
far
hello
world
how
are
you
samm@macmini ~>