Advertisement
cotolonco

Validar Ingreso tipo Int 2

Dec 6th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int variable;
  8.     cout << "Ingrese Numero: ";
  9.     //Si hay error ejecuta otra vez.
  10.     while (!(cin >> variable)){
  11.         cin.clear(); //Borra el error
  12.         cin.ignore(10000, '\n'); //limpiamos hasta encontrar un salto de linea
  13.         cout << "Ingrese Numero: ";
  14.     }
  15.     cout << "Su Numero: " << variable << endl;
  16.     return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement