要包含哪个标题以便调用`cout<<的std ::矢量<&_Ty GT;`?

时间:2012-12-12 13:37:12

标签: visual-c++ vector header-files cout

我正在尝试关注tutorial for the Boost Program Options library选项详细信息部分,我收到以下错误:

error C2679: "binary '<<' : no operator found which takes a right-hand operand
of type 'const std::vector<_Ty>'" (or there is no acceptable conversion)

我的代码如下。我猜我需要包含一个标题,但我不知道哪一个。

#include <boost/program_options.hpp>
#include <iostream>
#include <vector>
#include <string>

using std::cout;
using std::endl;
using std::vector;
using std::string;

namespace po = boost::program_options;

int options_description(int ac, char* av[])
{
    int opt;
    po::options_description desc("Allowed options");
    desc.add_options()
        ("help", "produce help message")
        ("optimization", po::value<int>(&opt)->default_value(10), 
            "optimization level")
        ("include-path,I", po::value< vector<string> >(), "include path")
        ("input-file", po::value< vector<string> >(), "input file")
    ;

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

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

    if (vm.count("include-path"))
    {
        cout << "Include paths are: " 
             << vm["include-path"].as< vector<string> >() << "\n"; // Error
    }

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

    cout << "Optimization level is " << opt << "\n";   

    return 0;
}

int main(int argc, char *argv[])
{
    return options_description(argc, argv);
}

1 个答案:

答案 0 :(得分:0)

不是严格地回答我的问题(我更喜欢这样做的标准库功能),但我找到了类似的问题,答案提供了一个在{{1上实现<<运算符的类接受ostream对象的类:

vector

我将此添加到我的代码中,现在可以编译。太糟糕了,教程中没有提到。

来源:Vector string with boost library C++ gives error