in your original example, you did an open with (ios::app | ios::in | ios::out | ios::binary).
Trouble is, you've just told the compiler that you want to append to the file (ios::app) and create/overwrite it (ios::in). This is what caused your problem.
When you changed to "fstream datafile("group.dat", ios::in | ios::out | ios::binary);" you removed the ios::app.
g++ (for the most part) tries VERY hard to follow the standard. (Vendors just try to make their products usable. ;-)