Advertisement
bal_gennady

Проверка на ввод символа

Oct 19th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <windows.h>
  2. #include <cstdlib>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  SetConsoleCP(1251);
  9.  SetConsoleOutputCP(1251);
  10.  
  11. int a;
  12. cout << "Введите число ";
  13. while (!(cin >> a))
  14. {
  15.     cin.clear();
  16.     while (cin.get() != '\n');
  17.     cout << "Неверный ввод. Повторите." << endl;
  18.     cout <<"Введите число ";
  19. }
  20. cout << a << endl;
  21.  
  22. system("pause");
  23. return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement