#### Archived

This topic is now archived and is closed to further replies.

# Reloading a file that has changed during the duration of the program

This topic is 5496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I noticed that if I use an ifstream to load a file, and then another program changes the file, and I close the file and open it again, it still loads the original file. I even tried making a pointer to an ifstream and then deleting it and recreating it, but I still couldn''t get the behavior I wanted. Is there some workaround or something dumb that I''m missing(the latter is far more likely )? 404x3

-~-The Cow of Darkness-~- If you see the image I am online

##### Share on other sites
*bump*

Am I totally screwed?

Yes.

##### Share on other sites
Close the file *before* the other program opens it.

##### Share on other sites
quote:
Original post by Hollower
Close the file *before* the other program opens it.

Ahh! That's something to try! I would deny access to the file from other programs, but that would defeat the purpose of my little project.

EDIT: OK, that worked, but I'm not sure that was the main problem. It seems that when the other program modifies the file, the file doesn't actually change... I'm creating an ofstream called in, oppening the file in ios::append, and using in >> "whatever"... this should be quite a bit easier to fix... I hope. Thanks!

[edited by - cowsarenotevil on June 4, 2003 9:27:43 PM]

##### Share on other sites
The file won''t be changed until the buffer is flushed. That occurs automatically when you insert an endl or when you use the flush method.

##### Share on other sites
quote:
Original post by Zipster
The file won''t be changed until the buffer is flushed. That occurs automatically when you insert an endl or when you use the flush method.

Thanks man! I think I have a curse whenever I try to do anything involving file i/o

• 11
• 20
• 12
• 10
• 34
• ### Forum Statistics

• Total Topics
631399
• Total Posts
2999854
×