如何解释“ regex e”行?

时间:2018-12-12 01:47:59

标签: c++ data-structures

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

  

{()} //平衡

     

{(\ n)} //平衡

     

{(} //不平衡

我使用的是我的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:\...'

是什么导致断言失败?

1 个答案:

答案 0 :(得分:3)

断言失败是由于assert()中的值是false。 assert()就是这样做的。从字面上看,如果括号之间的错误,那么整个问题就是导致断言失败。

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