C++ Checking for an integer.
问题 New to C++. Having issues correctly looping while handling errors. I am trying to check if user input is an integer, and is positive. do{ cout << "Please enter an integer."; cin >> n; if (cin.good()) { if (n < 0) {cout << "Negative.";} else {cout << "Positive.";} } else { cout << "Not an integer."; cin.clear(); cin.ignore(); } }while (!cin.good() || n < 0); cout << "\ndone."; When a non-integer is entered, the loop breaks. I feel like I am misunderstanding the inherent usage of cin.clear()