There is a little progamka, everything is nothing, but faced with a strange difficulty. Attached is a simple menu code that is wrapped in a do while loop and sends the user to other submenus via switch. Accepts the entered values from 0 to 7. When entering "0" the program is closed. Here's the problem: cin.clear () and cin.ignore () reset the flags and clear the buffer after each input, which eliminates the difficulty of incorrect input (select has type int), forcing it to repeat until it is entered Something intelligible, what the program expects. But there is one small "but." When entering numbers in cin, no errors are written, the cycle is simply restarted if the number does not fit. But if you enter any character, an error will appear in the stream, and after working with cin.clear () cin.ignore (), the select variable will magically (?) Be equal to "0" and the program will close. You can of course rearrange this function for 9, for example, but you want to understand the topic and do it more or less without crutches.
do { // Starting <do while> cycle for selection. Wro cout << "Input: "; cin >> select; // This var lives only in private sector in current class cin.clear(); //сбрасываем ошибку cin.ignore(numeric_limits<streamsize>::max(), '\n'); //удаляем все из буфера до перевода строки switch (select) { case 0: exit (0); case 1: menuVariables(); break; case 2: menuCycles(); break; case 3: menuArrays(); break; case 4: menuFunctions(); break; case 5: menuOperators(); break; case 6: menuPointers(); break; case 7: menuLibraries(); break; case 666: cout << "\nBingo, you're little satan's follower. But try something in 1-7 range, please.\n\n"; break; default: cout << "\nWrong input. Try again!\n" << endl; } } while (select < 1 || select > 7); } I can not find intelligible documentation on cin and its methods. Rather, that is - I can not overpower. Either I am stupid, or it is written in such a language, not for a beginner. I would be grateful if you tell me the solution and even briefly chew for the tankers. Thank!