简体   繁体   English

如何解释“ regex e”行?

[英]How can I interpret a 'regex e' line?

My function balanceFile returns true if my braces in a file are balanced. 如果我的文件中的括号是平衡的,则我的function balanceFile返回true。 For example: 例如:

{()} // balanced {()} //平衡

{(\\n)} // balanced {(\\ n)} //平衡

{(} // unbalanced {(} //不平衡

I am using a switch statement provided by my CS professor shown below: 我使用的是我的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));}

I am getting the following error: 我收到以下错误:

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

What is causing the assertion failure? 是什么导致断言失败?

The assertion failure is caused because the thing in assert() is false. 断言失败的原因是assert()为false。 That's what assert() does. 这就是assert()所做的。 Literally, the whole point of it is to cause an assertion failure if the thing between the brackets is false. 从字面上看,如果括号之间的错误,那么整个问题就是导致断言失败。

The reason regex_search(str, e) is false is because the regex e didn't match any part of the string str . regex_search(str, e)为false的原因是因为regex e与字符串str任何部分都不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM