如何在<string> boost::p rogram_options 中指定矢量的默认值
How do I specify a default value for vector<string> in boost::program_options
我确实想为位置参数提供一个默认值,如代码中的注释,但编译器抱怨。代码编译良好。我使用提升 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);
}
我需要给出默认值的文本表示,请参阅 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.")
我想这是帮助输出所必需的,在我的示例中可以
std::cout << desc << std::endl;
由于编译器不知道如何重载operator<<()
以进行vector<string>
,因此它抱怨。
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 具有默认值的引用获取函数
- 当给定默认值时,为什么此模板参数推导失败
- 从具有默认值的部分指定模板类继承时发生SWIG错误,具有不带默认值的正向声明
- 格式化浮点值:返回默认值
- 如何将数组部分初始化为某个默认值?
- asn1c 不会从 asn.1 模块中提取八位字节字符串的默认值
- 创建一个包含 c++ 默认值的环境文件
- C++(和 ROS) - 包含与前向声明引用,设置默认值和类型定义
- Makefile g++ 使用命令行中的 -D 变量进行编译,默认值
- Switch 语句(字符串)一直选择默认值,除非其为零
- 如何使用默认值将枚举声明为 extern
- 如何在提升程序选项中设置矢量<矢量>的默认值<string>
- 如何使用默认值为构造函数中的枚举赋值?
- 变量始终在函数中重置为默认值
- 如何在C++中提供模板化函数作为另一个函数的参数,默认值?
- 函数不返回默认值
- 具有公共范围与专用范围的默认值的C++的不同行为
- 在 c++ 中,如果我创建一个接受一个具有默认值的参数的构造函数 - 它会用作默认(空)构造函数吗?
- 实例化时结构字段中的默认值