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

Started by
6 comments, last by cowsarenotevil 20 years, 11 months ago
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
-~-The Cow of Darkness-~-
Advertisement
*bump*

Am I totally screwed?
-~-The Cow of Darkness-~-
Yes.
deny every other program access to your files.
Close the file *before* the other program opens it.
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]
-~-The Cow of Darkness-~-
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.
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
-~-The Cow of Darkness-~-

This topic is closed to new replies.

Advertisement