Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/04/2015, 18:50
Avatar de vangodp
vangodp
 
Fecha de Ingreso: octubre-2013
Mensajes: 934
Antigüedad: 10 años, 7 meses
Puntos: 38
Respuesta: Diferenciar entrada de datos por consola

Es el ejemplo de esta pagina modificado: http://www.cplusplus.com/reference/locale/isdigit/

Código C++:
Ver original
  1. // isdigit example (C++)
  2. #include <iostream>       // std::cout
  3. #include <string>         // std::string
  4. #include <locale>         // std::locale, std::isdigit
  5. #include <sstream>        // std::stringstream
  6.  
  7. int main () {
  8.     std::locale loc;
  9.     std::string str;
  10.     bool salir = false;
  11.     int n;
  12.    
  13.     do {
  14.         std::cout << "Entre con el numero" << std::endl;
  15.         std::cin >> str;
  16.         if (/**/ isdigit(str[0], loc) /**/) {
  17.             std::stringstream ( str ) >> n;
  18.             std::cout << "Es correcto el numero?->" << n << std::endl << "1-si \n0-no\n>>>";
  19.             int opc;
  20.             std::cin >> opc;
  21.             if ( opc == 1 ){
  22.                 salir = true;
  23.             }
  24.        
  25.         }else{
  26.             std::cout << "No es un numero" << std::endl;
  27.  
  28.         }
  29.        
  30.     } while ( !salir );
  31.    
  32.    
  33.     std::cout << "El numero es " << n << std::endl;
  34.  
  35.     return 0;
  36. }

Aun que puedes usar el ejemplo con ctype: http://www.cplusplus.com/reference/cctype/isdigit/