reloading data from text file

Hi all
I am reading data from a text file line by line using ifstream and I want to reload the content of the text file after changing some data in the original text.
Is that possible ?
closed account (zb0S216C)
Yes it's possible, but that would mean truncating all current data within the file and placing the specified content back into the file. The <fstream> library doesn't provide a way to modify individual sections of a file. What you must do is the following:

1) Open the file containing the data with std::ifstream.
2) Extract each line (preserving the white-spaces) from the file into a buffer such as a vector of strings.
3) Alter the data within the buffer.
4) Truncate the data within the file (remove the contents of the file).
5) Write all data from the buffer back into the file.
6) Close the stream.

Wazzak
Last edited on
Topic archived. No new replies allowed.