比较字符总是返回true
问题描述:
为什么hasParenthesis
总是评估为true?比较字符总是返回true
bool hasParenthesis = false ;
for(int i = 0; i < 255 && statement[i] != ';'; i++)
{
if(statement[i] == '(' || statement[i] == ')')
{
hasParenthesis = true;
break;
}
}
答
服务员,如果我的循环是一个!
假设statement
是std::string
,你就可以摆脱两个:
auto pos = statement.find_first_of(";()");
bool hasParenthesis = (pos != std::string::npos) && (statement[pos] != ';');
你不是hasParenthesis每次围绕环路重置为false .... – OmnipotentEntity
,什么是语句值? –
@OmnipotentEntity他已经在那里休息了,所以一旦碰到了if块,就没有更多的循环了。 –