Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. bool autobuses::Guardar(){ //SOLO SE PUEDE GUARDAR EL FICHERO SI SE HA CARGADO PREVIAMENTE Y NO LO ORDENA
  2.     if (cargado){
  3.         fichero.close();
  4.         fichero.clear();
  5.         fichero.open("Autobuses.dat",ios::in|ios::out|ios::binary|ios::trunc);
  6.         if(fichero.fail()) {
  7.             cout << "hubo un error en el archivo autobuses"<<endl;
  8.             fichero.close();
  9.             fichero.clear();
  10.             fichero.open("Autobuses.dat",ios::binary|ios::out);
  11.             fichero.close();
  12.             fichero.open("Autobuses.dat",ios::binary|ios::in|ios::out|ios::trunc);
  13.             //se crea aqui el fichero una vez nos da error
  14.  
  15.         }else{
  16.             autobus au;
  17.             fichero.seekp(0,ios::cur);
  18.             fichero.write((char*)&n,sizeof(int));
  19.             for(int i=0;i<n;i++){
  20.                 au=elementos[i];
  21.                 fichero.write((char*)&au,sizeof(autobus));
  22.             }
  23.             cout << "\nEl fichero se ha actualizado"<<endl<<endl;
  24.         }
  25.     }else{
  26.         cout << "\nEl fichero no esta cargado" << endl<<endl;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement