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

silverlight - Applying a style to ItemContainerStyle in C# -

c# - NullReferenceException in MySqlClient.NativeDriver -

php - Updating recent updates - Problem in procedure - Any other approach? -