繁体   English   中英

boost :: PO并且不能绑定到&#39;std :: basic_ostream <char> &amp;&amp;”

[英]boost::PO and cannot bind to ‘std::basic_ostream<char>&&’

我正在使用boost :: program_option编写程序,但无法使用其功能之一:

 po::options_description desc("Allowed options");
desc.add_options()
    ("include-path,I", po::value< std::vector<std::string> >(), "include path");

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

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

与boost.tutorial( http://www.boost.org/doc/libs/1_57_0/doc/html/program_options/tutorial.html )几乎相同

我得到这样的错误:错误:无法将'std :: basic_ostream'左值绑定到'std :: basic_ostream &&'std :: cout <<“包含路径为:” << vm [“ include-path”]。as>() << std :: endl;

我读过一些主题,例如: 错误:无法将'std :: basic_ostream'左值绑定到'std :: basic_ostream &&' 重载运算符<<:无法将左值绑定到'std :: basic_ostream &&'

但是我看不到与我的问题有关的联系。 我的平台:Fedora 20,Gcc 4.8.3,boost_1_57_0,我正在使用-std = c ++ 11 flat来编译代码。

您不能像这样打印vector<std::string> 这与Boost或Program Options无关:

std::vector<std::string> v = vm["include-path"].as< std::vector<std::string> >();
std::cout << "Include paths are: ";
for (auto& p : v)
    std::cout << "\n\t" << p;

生活在Coliru

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

namespace po = boost::program_options;

int main(int argc, char** argv) {
    po::options_description desc("Allowed options");
    desc.add_options()
        ("include-path,I", po::value< std::vector<std::string> >(), "include path");

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

    if (vm.count("include-path"))
    {
        std::vector<std::string> v = vm["include-path"].as< std::vector<std::string> >();
        std::cout << "Include paths are: ";
        for (auto& p : v)
            std::cout << "\n\t" << p;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM