爲什麼當輸入錯誤輸入時無限循環?我該如何糾正?當輸入錯誤輸入時無限循環無限循環
int operation;
while (true) {
cout << "What operation would you like to perform? Enter the number corresponding to the operation you would like to perform. ";
cin >> operation;
if (operation >= 1 && operation <= 5) break;
cout << "Please enter a number from 1 to 5, inclusive.\n";
}
這看起來與您最近問的問題非常相似。另一個問題發生了什麼? – 2010-10-06 19:20:50
啊,發佈它的人不一樣。這解釋了爲什麼我找不到它! – 2010-10-06 19:30:19