我不完全明白为什么我的 while 循环没有捕捉到任何这些条件
I don't exactly understand why my while loop is not catching any of these conditions
我正在尝试反向输出输入字符串,当用户输入“done”、“Done”或“d”时它将停止。这样,while 循环就不会捕获任何这些条件来停止循环。
#include`<iostream>
using namespace std;
int main() {
string userInput;
int i;
char output;
getline(cin, userInput);
while (userInput != "done" || userInput != "Done" || userInput != "d") {
for (i = userInput.size() - 1; i >= 0; --i) {
output = userInput.at(i);
cout << output;
}
cout << endl;
getline(cin, userInput);
}
return 0;
}
替换
while (userInput != "done" || userInput != "Done" || userInput != "d")
和
while ( ! (userInput == "done" || userInput == "Done" || userInput == "d") )
我正在尝试反向输出输入字符串,当用户输入“done”、“Done”或“d”时它将停止。这样,while 循环就不会捕获任何这些条件来停止循环。
#include`<iostream>
using namespace std;
int main() {
string userInput;
int i;
char output;
getline(cin, userInput);
while (userInput != "done" || userInput != "Done" || userInput != "d") {
for (i = userInput.size() - 1; i >= 0; --i) {
output = userInput.at(i);
cout << output;
}
cout << endl;
getline(cin, userInput);
}
return 0;
}
替换
while (userInput != "done" || userInput != "Done" || userInput != "d")
和
while ( ! (userInput == "done" || userInput == "Done" || userInput == "d") )