Problem med fstream
Heysa, jeg har noget bøvl med noget kode:this->lastupdatefile = new fstream("lastupdatefile.txt", ios::in | ios::out );
if(!(this->lastupdatefile))
{
cout << "(StatCalc::StatCalc)\t\t Error........reading lastupdatefile" << endl;
exit(1);
}
char buf[100] = { 0 };
// Denne linje virker! Skriver "abe" i filen
this->lastupdatefile->write("abe",3);
this->lastupdatefile->seekg(0);
this->lastupdatefile->read( reinterpret_cast<char *>(&(this->lastupdatetime)), 4 );
if(!this->lastupdatefile->eof() && this->lastupdatetime > 0)
{
strftime(buf, 99, "%T", localtime((const time_t *)&(this->lastupdatetime)));
cout << "(StatCalc::StatCalc)\t\t Timestamp have been read succesfully! got: " << buf << " from file" << endl;
}
else
{
this->lastupdatefile->seekp(4);
//Denne linjer virker IKKE!
this->lastupdatefile->write("abe",3);
this->lastupdatetime = time(0)-(60*60*24*7); //Start with time 1 week ago
strftime(buf, 99, "%T", localtime((const time_t *)&(this->lastupdatetime)));
this->lastupdatefile->seekp(0);
this->lastupdatefile->write( reinterpret_cast<const char *>(&this->lastupdatetime), sizeof(this->lastupdatetime) );
cout << "(StatCalc::StatCalc)\t\t Timestamp have been manually! set - to enable readings of 24 hours data pre the last update time: " << endl;
cout << "(StatCalc::StatCalc)\t\t The new offset for MySql query is: " << buf << " as starting time" << endl;
}
De to kommentarer indsat ved write() er mit spørgsmål. Hvorfor virker den ene? Og den anden ikke?