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
Post a Comment