如何在boost :: program_options中为vector <string>指定默认值

Mic*_*ael 12 c++ boost boost-program-options

我想为代码中的注释提供位置参数的默认值,但编译器会抱怨.这个代码编译得很好.我使用boost 1.46.1和g ++

int main(int argc, char *argv[]) {
    namespace po = boost::program_options;

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

    po::options_description desc("Options");
    std::vector<std::string> vec_str;
    std::string str;
    desc.add_options()
        ("foo,f", po::value< std::string >()->default_value(str), "bar")
        //("path,p", po::value< std::vector<std::string> >()->default_value(vec_str), "input files.")
        ("path,p", po::value< std::vector<std::string> >(), "input files.")
    ;

    po::variables_map vm;
    po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
    po::notify(vm);
}
Run Code Online (Sandbox Code Playgroud)

Mic*_*ael 13

我需要提供默认值的文本表示,请参阅http://lists.boost.org/boost-users/2010/01/55054.php.

即以下行:

 ("path,p", po::value< std::vector<std::string> > ()->default_value(std::vector<std::string>(), ""), "input files.")
Run Code Online (Sandbox Code Playgroud)

我想这是帮助输出所需要的,这可以在我的例子中

std::cout << desc << std::endl;
Run Code Online (Sandbox Code Playgroud)

由于编译器不知道如何重载operator<<()for vector<string>,它会抱怨.