如何将字符串传递给“validation_error”方法从Boost 1.46? [英] How to pass a string to "validation_error" method from Boost 1.46?

查看:138
本文介绍了如何将字符串传递给“validation_error”方法从Boost 1.46?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译一个由 Dalal和Triggs 发布的程序,它使用Boost图书馆。我在Boost方法 validation_error 中出现错误,因为作者使用的版本( 1.35 )与一个我正在使用( 1.46 )。

I'm trying to compile a program released by Dalal and Triggs which uses the Boost libraries. I got an error in the Boost method validation_error due to the differences between version which the authors used (1.35) and the one that I'm using (1.46).

旧版本 validation_error 方法使用的结构如下:

In the old version, the validation_error method used by the authors had the following structure:

validation_error(const std::string & what);

并且版本包含以下内容:

validation_error(kind_t kind, const std::string & option_value = "", 
                 const std::string & option_name = "");

在代码中,作者传递一个 string 到旧的 validation_error 方法(如下所示)。

In the code, the authors are passing a string to the old validation_error method (example below).

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());

这篇关于如何将字符串传递给“validation_error”方法从Boost 1.46?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆