Search:
Forum
General C++ Programming
What is wrong with the following file ha
What is wrong with the following file handling code snippet ??
Jan 30, 2010 at 2:47pm UTC
nipsun25
(1)
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();
Jan 30, 2010 at 6:02pm UTC
jsmith
(5804)
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.
C++
Information
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs