I'm trying to delete a line from a Db file that I've created.
I'm making a Db of people, which is consisted of id, first and last names - each one in a different line.
When I want to delete a record, I wanted to copy the part of the file after the record to another file, then copy it back to the position the record started (i.e the same data just one line before):
dataBase.seekg(nextRecordPosition,ios::beg); while (dataBase.peek()!=EOF) // copy a char to the temp file fileToCopy.put(dataBase.get()); dataBase.seekg(RecordPosition,ios::beg); while (fileToCopy.peek()!=EOF) dataBase.put(fileToCopy.get());
the problem is that the last line of the file is there twice - once from the new copy and one from the original file.
Is there a "smart" solution for that problem?
The other solution I have is copy the whole file beside the record-to-delete, then rename the new file to the original's name.