Just a niggling question:
If an error occurs, will the file handle be closed?Code:FILE* f = NULL; if ((f = fopen("C:\\test.dat", "w")) == NULL) { std::cerr << "Error writing file" << std::endl; exit(1); } // write or whatever fclose (f);
Just a niggling question:
If an error occurs, will the file handle be closed?Code:FILE* f = NULL; if ((f = fopen("C:\\test.dat", "w")) == NULL) { std::cerr << "Error writing file" << std::endl; exit(1); } // write or whatever fclose (f);
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
If fopen fails, then nothing was opened. Therefore, there's nothing to close. If something else generates an error, it would have to depend on the error I suppose. Usually, no. If you get a read error because you're trying to read past the EOF, no, it doesn't just close the file automatically.
Quzah.
Hope is the first step on the road to disappointment.