Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/10/2013, 23:55
ecfisa
 
Fecha de Ingreso: julio-2012
Mensajes: 133
Antigüedad: 12 años, 6 meses
Puntos: 22
Respuesta: manejo archivos txt

Hola flony.

Código C++:
Ver original
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #include<cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.   ifstream miArchivo ("nombres.txt", ifstream::in);
  11.   string linea, nombre;
  12.   bool found = false;
  13.    
  14.  
  15.   if (!miArchivo.is_open()) {
  16.     cout << "Error abriendo nombres.txt";
  17.     return  EXIT_FAILURE;
  18.   }
  19.  
  20.   cout << "ingrese el nombre buscado: ";
  21.   getline(cin, nombre);
  22.  
  23.   while (getline(miArchivo, linea, ','))
  24.     if (linea.find(nombre) != string::npos)
  25.       found = true;
  26.  
  27.   if (found)
  28.     cout << "el nombre buscado esta presente ";
  29.   else
  30.     cout << "el nombre buscado no esta presente";
  31.  
  32.   miArchivo.close();
  33.  
  34.   return EXIT_SUCCESS;
  35. }

Saludos