2017-02-24 13 views
3

, 내가 옵션 -i 모두 file0file1는하지만, -ifile0하지만 file1부스트 프로그램 옵션 여러 값이

를 수신 받고 싶은 나는 발견 나는 그 한 두 file0file1

boost::program_options이 작업을 수행받을 -i 옵션을 만들기 위해 a.out -i file0 -i file1를 입력합니다?

코드 숀 클라인에서 http://www.boost.org/doc/libs/1_62_0/libs/program_options/example/options_description.cpp

#include <boost/program_options.hpp> 

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

#include <iostream> 
#include <algorithm> 
#include <iterator> 
using namespace std; 

// A helper function to simplify the main part. 
template<class T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    copy(v.begin(), v.end(), ostream_iterator<T>(os, " ")); 
    return os; 
} 

int main(int ac, char* av[]) 
{ 
    try { 
     int opt; 
     int portnum; 
     po::options_description desc("Allowed options"); 
     desc.add_options() 
       ("help", "produce help message") 
       ("input-file,i", po::value< vector<std::string> >(), "input " 
         "file") 
       ; 

     po::variables_map vm; 
     po::store(po::command_line_parser(ac, av). 
       options(desc).run(), vm); 
     po::notify(vm); 

     if (vm.count("help")) { 
      cout << "Usage: options_description [options]\n"; 
      cout << desc; 
      return 0; 
     } 


     if (vm.count("input-file")) 
     { 
      cout << "Input files are: " 
       << vm["input-file"].as< vector<std::string> >() << "\n"; 
     } 

    } 
    catch(std::exception& e) 
    { 
     cout << e.what() << "\n"; 
     return 1; 
    } 
    return 0; 
} 
+2

가 당신'으로 값 '신고 할 ['multitoken'] (http://www.boost.org/doc/libs/1_63_0/doc/html/boost/program_options/typed_value.html#idp908724720-bb) 예상대로 행동해야합니다. –

+2

@SeanCline 주석 대신 대답으로 만드는 것을 고려하십시오. "("input-file, i ", po : value > (> -> multitoken(),"input file " –

답변

0

에서 적응 : multitoken이 예상대로 행동해야으로

은 값에 플래그.

("input-file,i", po::value<vector<std::string>>()->multitoken(), "input file")