how to open ofstream in exclusive mode
using ofstream, how can I open a file in exclusive mode? Someone told me that was the default, but in my test using VC++ 6.0 on XP that's not the case. I wrote a simple console program (see below) and all instances was able to successfully open and write to the file.
Code:
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
ofstream out("hello.txt",ios::app);
if(out.is_open())
{
cout << "File is open.. press <Enter> to continue ...";
out << "Hello World" << endl;
cin.get();
out.close();
}
else
{
cout << "File failed to open.. press <Enter> to continue ...";
cin.get();
}
return 0;
}