#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.
我已经在 Windows 7 和 lubuntu 上使用 QT 和 Code::blocks 尝试过这个程序。它们都无法创建 Grades.dat 文件。