【问题标题】:Boolean expression parse and evaluation in C++C++ 中的布尔表达式解析和求值
【发布时间】:2012-05-13 18:01:45
【问题描述】:

我需要在 C++ 中运行时评估简单的布尔函数。这些函数作为字符串从文件中读取。是否有任何可用的库可供我使用?

我查看了BuDDy,但听起来它不解析字符串。

【问题讨论】:

标签: c++ boolean expression expression-evaluation


【解决方案1】:

使用 boost 库 (lexical_cast.hpp)

bool a = boost::lexical_cast<bool>("true"); //true
bool b = boost::lexical_cast<bool>("0"); //false

或者去这里num_get facet and stringstream conversion to boolean - fails with initialised boolean?

【讨论】:

    猜你喜欢
    • 2013-08-04
    • 1970-01-01
    • 2012-02-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 2010-11-29
    • 2015-08-03
    相关资源
    最近更新 更多