Pergunta

I do want to give a default value for the positional parameter as in the comment in the code, but the compiler complains. The code as it is compiles fine. I use boost 1.46.1 and 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);
}
Foi útil?

Solução

I need to give a textual representation of the default value, see http://lists.boost.org/boost-users/2010/01/55054.php.

I.e. the following line works:

 ("path,p", po::value< std::vector<std::string> > ()->default_value(std::vector<std::string>(), ""), "input files.")

I guess this is needed for the help output, which could in my example

std::cout << desc << std::endl;

Since the compiler doesn't know how to overload the operator<<() for vector<string>, it complains.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top