c++ - cin skipping in while -


why cin being skipped in following while?

int main() {         int option;         cin >> option;         while(!cin.good()) {                 cout << "looping" << endl;                 cin >> option;         } } 

errors in iostreams sticky. need clear error state before cin works again.

int main() {         int option;         cin >> option;         while(!cin.good()) {                 cout << "looping" << endl;                 cin.clear(); // ignore erroneous line of input:                 cin.ignore(numeric_limits<streamsize>::max(), '\n');                 cin >> option;         } } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -