当我输入 start 然后程序输出 else 函数,即使我满足了条件,我也尝试了 && 但它仍然没有用。任何答案将不胜感激。
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main ()
{
float timer;
bool end;
std::string input;
end = false;
cout << "Enter start then a number to count down from" << ".\n";
while (end == false){
cin >> input;
if (input.find("end" || "End") != std::string::npos)
end = true;
else if (input.find("start" || "restart" || "Start" || "Restart") != std::string::npos)
{
cin >> timer;
while (timer>0){
timer -= 0.1;
Sleep(100);
cout << timer << ".\n";
}
cout << "Finished! Enter restart then another number to perform another countdown, or enter end to close the program" << ".\n";
}
else
cout << "Enter start" << ".\n";
}
return 0;
}
最佳答案
替换
if (input.find("end" || "End") != std::string::npos)
与:
if (input.find("end") != std::string::npos || input.find("End") != std::string::npos)
与您的其他 if
类似。
你的表达意思似乎很明显,但当你分解它时,它真的没有意义。 find
需要一个字符串,"end"|| "End"
不是字符串。
关于c++ - 或者接线员不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19690826/