Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool autobuses::Guardar(){ //SOLO SE PUEDE GUARDAR EL FICHERO SI SE HA CARGADO PREVIAMENTE Y NO LO ORDENA
- if (cargado){
- fichero.close();
- fichero.clear();
- fichero.open("Autobuses.dat",ios::in|ios::out|ios::binary|ios::trunc);
- if(fichero.fail()) {
- cout << "hubo un error en el archivo autobuses"<<endl;
- fichero.close();
- fichero.clear();
- fichero.open("Autobuses.dat",ios::binary|ios::out);
- fichero.close();
- fichero.open("Autobuses.dat",ios::binary|ios::in|ios::out|ios::trunc);
- //se crea aqui el fichero una vez nos da error
- }else{
- autobus au;
- fichero.seekp(0,ios::cur);
- fichero.write((char*)&n,sizeof(int));
- for(int i=0;i<n;i++){
- au=elementos[i];
- fichero.write((char*)&au,sizeof(autobus));
- }
- cout << "\nEl fichero se ha actualizado"<<endl<<endl;
- }
- }else{
- cout << "\nEl fichero no esta cargado" << endl<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement