#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main() {
fstream inOutGrades( "grades.dat", ios::in | ios::out | ios::binary );
if ( !inOutGrades ) {
cerr << "The file could not be opened." << endl;
exit(1);
}
return 0;
}
//Output is
The file could not be opened.
I’ve tried this program wioth QT and Code::blocks at windows 7 and lubuntu.They all can’t create the grades.dat file.
Remove
ios::inand the file should be created. You cannot specifyios::inif a file does not exist. However, if you addios::truncyou are able to specify bothios::inandios::outsince you are starting with an empty file.