Hey
I am a software engineering student and just started my C++ course.
I need help with understanding cin.fail() behavior. As far as i understood, doing some research on it, it returns true in case there is a failbit or a badbit.
Here i wrote a short program to test its behavior
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
usingnamespace std;
int main(){
int temp;
do{
cin.clear();
cin >> temp;
}while(cin.fail());
cout << temp;
}
My original intention was for it to prompt user for input once failbit was detected. However, for unknown reason it enters endless loop once i enter an illegal character. Could someone explain why? Thanks