2012-11-17 60 views
1

在此代碼中,我得到了enourmous錯誤另一個增壓誤差

static void ParseTheCommandLine(int argc, char *argv[]) 
{ 
int count; 
int seqNumber; 

namespace po = boost::program_options; 

std::string appName = boost::filesystem::basename(argv[0]); 

po::options_description desc("Generic options"); 
desc.add_options() 
("version,v", "print version string") 
("help", "produce help message") 
("sequence-number", po::value<int>(&seqNumber)->default_value(0), "sequence number") 
("pem-file", po::value< vector<string> >(), "pem file") 
; 

po::positional_options_description p; 
p.add("pem-file", -1); 

po::variables_map vm; 
po::store(po::command_line_parser(argc, argv). 
      options(desc).positional(p).run(), vm); 
po::notify(vm); 

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

cout << "Sequence number is " << seqNumber << "\n"; 

exit(1); 

../../../FIXMarketDataCommandLineParameters/FIXMarketDataCommandLineParameters.hpp|98|error:在「不匹配「運算符< <」 (std :: basic_ostream> &)(& std :: cout)),((const char *)「Pem files are:」))< < ((const boost :: program_options :: variable_value *)vm.boost :: program_options :: variables_map :: operator [](((const std :: string &)(& std :: basic_string,std :: allocator>(((const char *)「pem-file」),((const std :: allocator &)((const std :: allocator *)(& std :: allocator( )))))))))) - > boost :: program_options :: variable_value ::與T = std :: vector,std :: allocator>,std :: allocator,std :: allocator>>>'|

+0

你真的應該顯示'vm' ... – Cornstalks

+3

可能類似錯誤的聲明,你會從COUT <<矢量()獲得; – nurettin

+0

歡迎來到Stack Overflow。請記住**問一個問題**。 –

回答

3

向量不執行ostream & operator<<(std::ostream &)

你或許應該這樣做:

cout << "Pem files are: "; 
for (auto & x : vm["pem-file"].as< vector<string> >()) 
    cout << x << "\n"; 
+0

它是教程的一部分http://www.boost.org/doc/libs/1_52_0/doc/html/program_options/tutorial.html#id2607140 – user1676605

+0

@ user1676605:boost教程可能有錯誤。 – ybungalobill

+0

gotcha謝謝。我通過模板解決了它< class T > std :: ostream&operator <<(std :: ostream&os,const std :: vector &v) { os <<「[」;對於(typename std :: vector :: const_iterator ii = v.begin(); ii!= v.end(); ++ ii) os <<「 } os <<「]」; return os; } – user1676605