如果我在文件中的大括号是平衡的,我的函数 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/