Advertisement
xlujiax

Creacion_Archivo_Secuencial

Oct 25th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using std::cerr;
  5. using std::cin;
  6. using std::cout;
  7. using std::endl;
  8. using std::ios;
  9.  
  10. using namespace std;
  11.  
  12. #include <fstream> //Flujo de archivo
  13. using std::ofstream; //Flujo de archivo salida
  14.  
  15. #include <cstdlib>
  16. using std::exit;  //Prototipo de la funcion exit
  17.        
  18.  
  19.  
  20. int main(int argc, char** argv) {
  21.     ofstream archivoClienteSalida("clientes.dat",ios::out);  //El constructor abre el archivo
  22.     if (!archivoClienteSalida){
  23.         cerr << "No se puede abrir el archivo." << endl;
  24.         exit(1);
  25.     }
  26.     cout << "Escriba la cuenta, nombre y saldo." << endl << "Escriba fin de archivo para terminar la entrada.\n";
  27.    
  28.     int cuenta;
  29.     char nombre[30];
  30.     double saldo;
  31.    
  32.     while(cin >> cuenta >> nombre >> saldo){
  33.         archivoClienteSalida << cuenta << ' ' << nombre <<' ' << saldo << endl;
  34.         cout << "? ";
  35.     }
  36.  
  37.     return 0; //Destructor de ofstream cierra el archivo
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement