0

Hi.

I'm trying to delete a line from a Db file that I've created.

I'll explain:

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.

Thanks!

Edited by shilosimi: misstype

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by tkud
0

The problem might not be from the code fragment posted here. Post your full working code.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.