![]() |
|
|
#1 | ||
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
c++ problem: overwriting a file
I'm ouputting the contents of a linked list to a file. It works when there is no existing file. However, when a file already exists with valid content, I can import the data to a linked list, I can modify and display the contents which correctly amends the list but it won't write the modified list to file.
Code:
Tracing through the while loop, it iterates the correct number of times so it looks like the data is being written to file but no such luck... |
||
|
|
|
|
|
#2 |
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
It turns out data was never actually opened unless it didn't exist in the directory... I thought another function had already taken care of it.
Cool... Last edited by Karim : 02-12-2005 at 02:17 AM. |
|
|
|
|
|
#3 |
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
Hmm...
adding data.open("filename") enables me to overwrite to an existing file but removes the ability to create a file when none exists... |
|
|
|
|
|
#4 |
|
College Starter
Join Date: Oct 2000
Location: Calgary
|
quadruple dola.. that's a first...
It turns out if the file existed, the output stream was never opened and vice versa. I'm not sure how I fixed it but it works now... For those more skilled than me, isn't it better (safer) to use a fstream when reading/writing to the same file? In this case they were separated because all the reading was done first, stored in a list, and then written to file. |
|
|
|
|
|
#5 |
|
Pro Starter
Join Date: Oct 2000
Location: Cary, NC
|
This all depends on how you were opening "data". You can specify modifiers that determine if you overwrite the file, append to the file, etc. Check the working directory as well, maybe you have extra files elsewhere now...
__________________
-- Greg -- Author of various FOF utilities |
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|