I am writing a program that uses a file on the disk to store configuration data, and this program both reads and writes to this file during execution. I want users to be able to run multiple instances of my program, but it is highly undesirable for both instances to believe they have write access to the configuration file. In anticipation of this problem, I had planned for my application to attempt to open the file for writing, and, if it finds that the open operation failed, it goes into a contingency state where it forgoes use of the configuration file.
Unfortunately, this scheme doesn't work, because fstream is more than happy to open the same file, for writing, multiple times!
Here is a test program I wrote: