On Tue, 11 Nov 2003 22:09:12 -0800, Maximus <ik*********@videotron.ca>
wrote:
Hi,
I'm not verry good at c++ but I was asking myself this question... Could
it
be possible to store a variable into a file and load it back into the
same
variable? What I would like to do is save a structure into a file so I
can
load it back the next time my program run into the same structure.
Thanks, Max.
Most complicated thing is to remember the name of the file, so let's call
it remember.dat
write some stuff to the file:
struct POD {... }; // something in there, no pointers !
POD data;
#include <fstream>
ofstream os("remember.dat"); // creates a file to remember
os.write((const char*)&data,sizeof(POD));
If you want to read this back
POD data;
#include <fstream>
ifstream is("remember.dat"); // opens the data
is.read((char*)&data,sizeof(POD));
--
grzegorz