PLEASE Help - Binary record deletion

Im a beginner with binary files. The thing is, i was trying to make a programme to create a binary record for instance a record of 10 rooms. now i wanted to make a program to delete one of those rooms say room number 8.

I made a program to copy all the other files apart from room number 8 to another binary file ( so room 8 is deleted in new binary file )

But when i transfer the files back, its obvious that when i write over the old binary file which has 10 rooms, there is one extra than the new binary file ( which does not have room num 8 thus has a total of 9 rooms )
So the last record is repeatd.

eg-
main room file has ( 1,2,3,4,5,6,7,8,9,10 )
transfer to new file
temporary file to delete has ( 1,2,3,4,5,6,7,9,10 )
transfer to main file
After transfer main room file has ( 1,2,3,4,5,6,7,9,10,10 )

so here i get the last record is repeated. There is some logical error. could someone please help. its urgent i need to submit the project within three days.
Last edited on
Clear the file before rewriting the new data to it.

You should be able to create a new ofstream object with the desired filename, thus opening the file for writing; the file is cleared by default with ofstream, I think.
Yea thats exactly what i wanted to know. How do i clear the previous binary file. ? il try ofstream and see if it works.

But any other alternative??
Last edited on
Topic archived. No new replies allowed.