2012-02-23 1 views
0

はここに書きたいコードです。ブーストライブラリを使用したベクトル文字列C++はエラーを返します

int opt; 
po::options_description desc("Allowed options"); 
desc.add_options() 
    ("help","produce help message") 
    ("compression",po::value<int>(&opt)->default_value(10),"optimization level") 
    ("include-path,I", po::value< std::vector<std::string> >(), "include path") 
    ("input file", po::value< std::vector<std::string> >(),"input file") 
    ; 


po::variables_map vm; 
po::store(po::parse_command_line(argc,argv,desc),vm); 
po::notify(vm); 

if (vm.count("help")){ 
    std::cout <<desc<<"\n"; 
    return 1; 
} 
if (vm.count("compression")){ 
    std::cout<<"Compression level was set to"<<vm["compression"].as<int>()<<".\n"; 
} else { 
    std::cout << "compression level was not set.\n"; 
} 
if (vm.count("include-path")){ 
    std::cout << "Include paths are:  " << vm["include-path"].as< std::vector<std::string> >()<< "\n"; 
    } 

コンパイラは、私が含まパスをパラメータを印刷する場合、最終的なステートメントのエラーが発生します。それが与える誤差がある

rx_timed_samples.cpp:62:96:エラー:STD」で 'オペレータ< <' の不一致::オペレータ< <((* & STD [_Traits = STD :: char_traits付き] (const char *) "を含む)< <(& vm.boost :: program_options :: variables_map :: operator []((* & std :: basic_string *) "include-path")、((const std :: allocator)(& std :: allocator())))))))))))))))))))))) - > boost :: program_options :: variable_value :: T = std: :vector、std :: allocator >> '

私はそれを手に入れませんか?助けてください。

答えて

1

ベクトルを処理できるストリーム演算子の特殊化が必要です。

template<class T> 
std::ostream& operator <<(std::ostream& os, const std::vector<T>& v) 
{ 
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout, " ")); 
    return os; 
} 
1

ここでの問題は、 <演算子がstd::vector<std::string>に定義されていないことです。この呼び出しに必要なもの:

std::cout << "Include paths are:  " << vm["include-path"].as< std::vector<std::string> >()<< "\n"; 
関連する問題