By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,849 Members | 2,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,849 IT Pros & Developers. It's quick & easy.

ofstream is_open

P: n/a
ofstream blah;

IS:

if (blah == NULL)
{
}

THE SAME AS:

if (!blah.is_open())
{
}

I think the answer is NO since blah will never equal NULL, since I
could not find a operator for ofstream for == and blah is a instance
of a class and not a reference or a pointer therefore the statement
blah == NULL makes no sense.
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Steven C" <st********@hotmail.com> wrote in message
news:76**************************@posting.google.c om...

I think the answer is NO since blah will never equal NULL, since I
could not find a operator for ofstream for == and blah is a instance
of a class and not a reference or a pointer therefore the statement
blah == NULL makes no sense.


The base class for the streams overload both a conversion operator for void*
and also operator!. Hence you can say things like:
if(blah)
or
if(!blah).

These are mapped to the blah.fail() (which emcompasses more errors than not
being
open).

Jul 22 '05 #2

P: n/a
On 11 Dec 2003 16:51:29 -0800, Steven C <st********@hotmail.com> wrote:
ofstream blah;

IS:

if (blah == NULL)
{
}

THE SAME AS:

if (!blah.is_open())
{
}

I think the answer is NO since blah will never equal NULL, since I
could not find a operator for ofstream for == and blah is a instance
of a class and not a reference or a pointer therefore the statement
blah == NULL makes no sense.


ofstream has a conversion operator to void*, so comparing it with NULL
is perfectly valid.

However, they have completely different meanings, the first checks if
failbit or badbit are true, the second tests if blah.is_open() returns
false. Those are completely different tests.

Hence the answer is no, but for a different reason.

--
Sam Holden
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.