如何将字符串传递给 Boost 1.46 中的"validation_error"方法?
How to pass a string to "validation_error" method from Boost 1.46?
我正在尝试编译Dalal和Triggs发布的一个使用Boost库的程序。我在Boost方法validation_error
中遇到了一个错误,因为作者使用的版本(1.35
)和我正在使用的版本之间存在差异(1.46
)。
在旧版本中,作者使用的validation_error
方法具有以下结构:
validation_error(const std::string & what);
我运行的Boost版本有以下内容:
validation_error(kind_t kind, const std::string & option_value = "",
const std::string & option_name = "");
在代码中,作者将string
传递给旧的validation_error
方法(下面的示例)。
std::ostringstream ost;
ost << "value " << *value
<< " greater than max value " << max;
throw po::validation_error(ost.str());
如何将此string
传递到新版本的validation_error
?
你可以做一些类似的事情
throw boost::program_options::validation_error(
boost::program_options::validation_error::invalid_option_value,
"option name",
*value
);
或
throw boost::program_options::invalid_option_value(ost.str());
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- .cpp和.h文件中的模板专用化声明
- 反向给定链表中的K节点
- 正在查找文档以获得PS4平台的C++中的设备信息
- enum是C++中的宏变量还是整数变量
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 将字符串存储在c++中的稳定内存中
- 文本文件中的单词链表
- 递归函数计算序列中的平方和(并输出过程)
- 如何从C++中的依赖类型中获得它所依赖的类型
- C++中的"inline"关键字
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 如何使用 < 和 > 命令获取 c++ 中的输入和输出?
- 用C++中的一个变量定义一个常量
- vector.resize()中的分配错误
- 使用指针从C++中的数组中获取最大值
- arr[-1]在c++中的奇怪行为
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 将值指定给向量(2D)的向量中的某个位置
- 内置函数可查看CPP中的成员变量