c++ - 如何解释 'regex e' 行?

标签 c++ data-structures

如果我在文件中的大括号是平衡的,我的函数 balanceFile 将返回 true。例如:

{()} // balanced

{(\n)} // balanced

{(} // unbalanced

我正在使用我的 CS 教授提供的 switch 语句,如下所示:

case 8: {
        istringstream iss("{(\n)}");
        assert(balanceFile(iss));
        string str = strCout.str();
        regex e("pair *matching *\\( *and *\\).*\\npair*matching *\\{ *and *\\}");
        assert(regex_search(str, e));}

我收到以下错误:

Assertion failed: regex_search(str,e), file c:\...'

断言失败的原因是什么?

最佳答案

断言失败是因为assert()里面的东西引起的是假的。这就是 assert() 所做的。从字面上看,它的全部意义在于,如果括号之间的内容为假,则导致断言失败。

regex_search(str, e) 为假的原因是因为正则表达式 e 不匹配字符串 str 的任何部分。

关于c++ - 如何解释 'regex e' 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53734939/

相关文章:

c++ - QObject::connect: QT 上没有这样的插槽

algorithm - 我应该买哪些数据结构和算法的书?

arrays - 为数组中的每个元素找到最后一个较小或相等的数字?

c++ - 如何从文件中读取

命名空间中的 C++ 前向声明和友元

c++ - 有效的 c++ 项目 3 示例

database - 使用表过滤器查询全文搜索的最佳方式

c++ - 读取此文件以便稍后操作的最佳方式?

arrays - 数据结构面试: find max number in array

c++ - C++ 中的运行时类型和属性识别