比较字符总是返回的
comparing character always returns true
为什么 hasParenthesis
总是评估为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] != ';');
for循环启动时,将hasParenthesis
设置为false。有了您目前的真实,一旦布尔值的真实,当循环重新征服时,它将始终是正确的。因此,从布尔false开始for循环逻辑。
这是一个简化的骨架:
bool hasParenthesis;
for(){
hasParenthesis = false;
if(){
hasParenthesis = true;
}
}
相关文章:
- std::stringstream 返回字符 *
- 使用字符串 c_str() 返回字符*
- 从函数返回字符*
- Flex/Bison从C 中的扫描仪返回字符令牌
- 为什么getServicedisplaynamew()和getServicedisplaynamea()返回字符中不同所
- std::string::d ata() 不会返回字符*
- 在 c++ 中返回'/n'字符
- C 如何编写返回字符指针的功能
- 从函数返回字符*不起作用
- 为什么我的函数在应该返回字符时返回垃圾
- C++ Wrting 一个函数,该函数从名为 line_of_input 的字符串中返回字符"a"、"e"、"i"的出现次数
- 删除返回字符*的位置
- 通过赋值运算符返回字符数组
- 字符到 ASCII 代码转换并返回字符
- 尝试返回字符数组
- Arduino,返回字符数组的函数
- C++返回字符指针并打印
- 使用 std::cin >>时可以丢弃返回字符吗?
- 如何从课堂上返回字符*
- 如何使用模板返回字符值