954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

deketing a line from file

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!

shilosimi
Newbie Poster
4 posts since May 2011
Reputation Points: 10
Solved Threads: 0
 

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

tkud
Posting Whiz in Training
235 posts since Sep 2009
Reputation Points: 13
Solved Threads: 46
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: