Hey,
I've made an array of structures. I did so by making an pointer to an array of pointers (by dynamic allocation),and allocate the address of a structure to one of these last pointers. Everything should be written to a binary file.
Here's the code:
likewise, the size needs to be the size of a student, not a student pointer.
now the reader will keep taking tying to read till end of file is reached, but the end of file flag doesn't come up when the last element is reached but when you try to access one more, so it should be:
There was only one problem when I tried to add some records to the existing file: the last added records could not be read properly (hence it understood how many records there were!). So I changed something in
the writing code, something that seemed rather strange: you dereference and then ask for the address (which seems unnecessary to me, I think).
So I changed
outfile.write((char*)&*(x[i]),sizeof(STUDENT));
into
outfile.write((char*)(x[i]),sizeof(STUDENT));
Now it reads the last added records properly! Although I do not understand why it should not read properly when you use &*(x[i]):