Hi there. I've got a problem which I have been stuck for a good whole week already. Tried alot of different methods but to no avail. I'm still new at this, hopefully someone can help me with this? I've got a binary file which I have created in a previous program. So this second program I'm working on is suppose to allow me to edit the binary file which I created. Struct is still the same, I'm still able to open and read the binary file too. Now the problem is that I cant seem to edit and save the updates back into the file. Is there something I'm doing wrong?
This is just part of the program, in this part I want to increase the variable "size" by 1. size DOES increase by 1, but when I open the binary file again, it goes back to its default value
Code:
void appendStaff (fstream& afile, char nameDat[])
{
ABC staff[MAX];
int size;
afile.open (nameDat, ios::in | ios::out | ios::app | ios::binary);
afile.read (reinterpret_cast <char *> (&staff), sizeof (staff));
afile.read (reinterpret_cast <char *> (&size), sizeof (size));
size = size + 1;
afile.write (reinterpret_cast < const char *> (&size), sizeof (staff));
cout << size <<endl;
afile.close();
}