Hi all...

I have not seen a faq or post that matches my problem. Hopefully, you folks can lend me your expertise once again.

I'm using random files to store some data. When I use ofstream to write the data to the file, it stores it just fine and ifstream variables can read it properly.

However, if I define a variable as fstream and write to that same file, only the record which it had modified is correctly written. The rest of the file becomes garbage (as interpreted by the ifstream variable).

In addition, when looping through the contents of the file using a while loop, the first record is skipped. Why is this? Using the same while loop with an ifstream variable finds all the records just fine! Including the first record!

Correct me if I'm wrong, but aren't ifstream and ofstream subclasses of the fstream class? Shouldn't I be able to read the data from the file just fine with the fstream variable? Why does modifying one record corrupt the rest of the file when using fstream if it wasn't originally written by a fstream variable? Is this a known issue?

Your insights please. Thanks in advance.