|
-
January 30th, 2009, 06:22 AM
#1
Which file mode to use
My problem is that I have to modify a record in a text file. Suppose there are 10 records in a file and I have modify the 5th record. I am trying to do this with the help of tellg and seekp.
Whenever I use fout.open("filename"), the previous contents of the file are discarded/deleted. Which filemode do I use which allows me to use seekp and at the same time, doesn't delete the contents of the file. I cannot use ios::app because seekp can't be used then. Even ios::ate is deleting the contents of the file.
If there is no file mode to do this, then I can think of only one solution, i.e. to copy till the 4th record to another file, write the modified 5th record to the second file, and then write the remaining records from the first file to second file. After this, remove the first file and rename the second file.
Please help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|