PDA

View Full Version : [OT] C++, fstream



FirEdge
03-10-2002, 06:23 AM
I have some problems with my engine, as I try to save/restore configuration from a class to the hard drive.

I overloaded the fstream operators this way:

fstream& operator>>( fstream& istr, CConfig& C );
fstream& operator<<( fstream& ostr, CConfig& C );

my file stream is initialized this way:

cfgfile = new fstream( DEFAULT_CFG_FILE, ios::in | ios: http://www.opengl.org/discussion_boards/ubb/redface.gifut | ios::binary );

initialized this way:

if (cfgfile && (cfgfile->eof() == 0))
*cfgfile >> *cfg;
else
cfg->Default();

and saved this way:

*cfgfile << *cfg;
cfgfile->close();

problem : no data is wrote on the hard drive, the operator code is the following:

fstream& operator<<( fstream& ostr, CConfig& C )
{
ostr.seekp( 0, ios::beg );
int pos = ostr.tellp();
ostr << C.ID;
... other data writing code here ...
ostr << flush;
pos = ostr.tellp();
return ostr;
}

the first tellp returns 0, the second tellp returns 0.. I don't understand... can anyone help me ?

thank you in advance,

FirEdge
03-10-2002, 06:40 AM
Sorry, forgot to disable smilies, it was

cfgfile = new fstream( DEFAULT_CFG_FILE, ios::in | ios::out | ios::binary );

Lighthouse
03-10-2002, 07:05 AM
Post your question in comp.lang.c++ or somewhere equally suitable, I doubt you'll get a reply here. No, putting '[OT]' in the subject does not redeem you.