What is wrong with the following file handling code snippet ??

There seems to be some problem with the file pointer manipulation!
PS: 'bk' is an object of a class 'book'

fstream file;
file.open("Books.dat",ios::binary|ios::ate);
bookptr=file.tellg();
bk.read((char*)&bk,sizeof (bk));
bk.chng_stat('D');
bookptr-=sizeof(bk);
file.seekp(bookptr,ios::beg);
file.write((char*)&bk, sizeof(bk));
file.close();

In general it is a bad idea to write classes to file as streams of binary data. This will
not work if the class contains pointers (directly or indirectly) or if the class has any
virtual methods or virtual destructor.
Topic archived. No new replies allowed.