+ 6
Are you stuck with an infinite loop while using fail() in C++?
Lesson for today: don't forget to add: cin.sync(); OR for Linux users: cin.ignore(numeric_limits < streamsize >::max(), '\n'); after clear(); Example: while(true){ cout << "The limit is: "; cin >> limit; if (cin.fail()){ cout << "I don't know what to do with this. Please enter numeric limit greater than 0: " << endl << endl; limit = 0; cin.clear(); cin.sync(); //for Linux users: //cin.ignore(1000, '\n'); //cin.ignore(numeric_limits < streamsize >::max(), '\n'); } else{ break; } }
3 Réponses
+ 3
@Justyna
Thank you for sharing!
+ 1
hi you have a FACE BOOK
0
well done