Topic: Constructing ifstream for non-existent file is not a failure?
Author: Arch Robison <robison@kai.com>
Date: 1996/10/02 Raw View
According to the April 1995 and Jan 1996 working papers, there is
a difference between constructing an ifstream from a file name,
and using method ifstream::open.
Assume that file nonexistent-file does not exist.
Consider the following fragment:
std::ifstream f( "nonexistent-file" );
According to the drafts, f.good() is true after executing the fragment.
There are no words in the drafts that say otherwise. But if I use the
following alternative:
std::ifstream f;
f.open( "nonexistent-file" );
then the drafts say that f.good() is false.
This inconsistency bothers me for two reasons:
(a) Not setting the failbit seems gratuitously inconsistent with existing
practice. The old iostream distributed with Cfront sets the
failbit for both cases so that programmers can write stuff like:
ifstream f("can-of-worms") ;
if( !f ) cout<<"cannot open can-of-worms";
The draft breaks this documented idiom.
(b) The whole point of having failbit is to report failures.
Why report it in one case and not the other?
Is the inconsistency a feature of the standard? Or an oversight by omission
that needs clarification?
Arch D. Robison Kuck & Associates Inc.
robison@kai.com 1906 Fox Drive
217-356-2288 Champaign IL 61820
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]