我不太明白为什么我的While循环没有捕捉到任何这些情况 [英] I don't exactly understand why my while loop is not catching any of these conditions
本文介绍了我不太明白为什么我的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") )
这篇关于我不太明白为什么我的While循环没有捕捉到任何这些情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文