Goodnight. A question from a newbie. There is a program, it does something. For some reason, it takes data from the user and writes it to a variable of type int. Of course, when entering something other than an integer, it goes into a loop. Found on the Internet a good solution for processing input:

int a; cin >> a; cin.clear(); cin.ignore(numeric_limits<streamsize>::max(), '\n'); 

Everything works, like even the principle understood. But there is one small BUT. As planned, when you enter "0" the program quits. For any incorrect input from cin 0 is extracted and the control structure has time to eat it and complete the program. :) how can you get out of this situation without changing the logic of work? (put the output at 9 instead of zero - the first thing I thought about).

  • Well, who's stopping to handle incorrect input? You don’t even check the status of cin ... - Harry

0