J
junw2000
Below is simple code:
#include <iostream>
int main(){
int i;
while(1){
while(!(std::cin >> i)){
std::cout<<"Invalid input i: "<<i<<'\n';
}
std::cout<<"input i: "<<i<<'\n';
}
}
When I input a non-integer, like 'r', the code will loop infinitely.
What is the problem? How to revise it?
Thanks.
#include <iostream>
int main(){
int i;
while(1){
while(!(std::cin >> i)){
std::cout<<"Invalid input i: "<<i<<'\n';
}
std::cout<<"input i: "<<i<<'\n';
}
}
When I input a non-integer, like 'r', the code will loop infinitely.
What is the problem? How to revise it?
Thanks.