Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

How can we read/write structures from/to data files?
There 2 function given in C++. They are fread() & fwrite(). Using them we can read & write structures
from/to data files respectively.

Basic representation:
fread(&structure, sizeof structure,1,fp);

 fread function recieves a pointer to structure and reads the image(memory) of the
structure as a stream of bytes. Sizeof gives the bytes which was occupied by structure.

fwrite(&structure, sizeof structure,1,fp);

 fwrite function recieves a pointer to structure and writes the image(memory) of the
structure as a stream of bytes. Sizeof gives the bytes which was occupied by structure.