Check out the following code:

Code:
obook.write(reinterpret_cast< const char * >(&newBook), sizeof(Book));
...where obook is an ofstream variable that opens a file using ios::ate and newBook is an instance of a class I made.

The problem is that when I write to the file, around 70% of the time, it will work. There is however, a good 30% of the time where it just writes garbage. Even when I'm entering the exact same data twice (exactly the same except the key field). Why would this happen?

Has anyone ever had this problem? I'd appreciate your insights. Thanks.