goodbit and failbit of cin
Hi,
Please take a look at this
Code:
int choice;
do{
cin >>choice;
switch{
case 1: cout << "Valid choice" <<endl;
case 2: cout<< "leaving loop" << endl;
default: cout << "Invalid choice" << endl;
}
}while(choice !=2)
When i input a non integer value such as a char 'a' , this segment of the loop executes infinitely. I believe the cin stream have set failbit because of the incorrect format of input. However, how can i set it back to goodbit? I tried cin.clear() but it didnt work.
Thanks