我正在尝试关注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);
}
答案 0 :(得分:0)
不是严格地回答我的问题(我更喜欢这样做的标准库功能),但我找到了类似的问题,答案提供了一个在{{1上实现<<
运算符的类接受ostream
对象的类:
vector
我将此添加到我的代码中,现在可以编译。太糟糕了,教程中没有提到。