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);
Printable View
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);
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.