C
Count Dracula
To open a file, a utility I have uses basically the following
std::ifstream input;
input.open(filename);
if (!input.is_open())
// write error message, throw exception
Now if "filename" is an existing directory instead of a file, then
when
compiled with g++ version 4.1.1, no error message is written and no
exception is thrown. If later an attempt is made to read something
from input, an exception is thrown.
When compiled with a recent version of VC++, the same code writes
an error message and throws an exception if "filename" happens to be
a directory instead of a regular file.
Is this a bug in g++? Or is it not enough to use is_open() as shown
when using g++?
std::ifstream input;
input.open(filename);
if (!input.is_open())
// write error message, throw exception
Now if "filename" is an existing directory instead of a file, then
when
compiled with g++ version 4.1.1, no error message is written and no
exception is thrown. If later an attempt is made to read something
from input, an exception is thrown.
When compiled with a recent version of VC++, the same code writes
an error message and throws an exception if "filename" happens to be
a directory instead of a regular file.
Is this a bug in g++? Or is it not enough to use is_open() as shown
when using g++?