473,698 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ofstream is_open

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
2 2624

"Steven C" <st********@hot mail.com> wrote in message
news:76******** *************** ***@posting.goo gle.com...

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
On 11 Dec 2003 16:51:29 -0800, Steven C <st********@hot mail.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2905
by: Tom Johnson | last post by:
Hi all, I cant believe that Im stuck on such simple code, but I am so... Im trying to open a text file for writing but can never get the file to initially open. Heres what Im having trouble with. ----------------------------------------------- #include <iostream.h> #include <fstream.h> void main()
2
2813
by: Colum | last post by:
Hi, I am trying to write data out to a file on floppy disk, If the disk is present in the drive the program runs fine and outputs the data correctly, however if the disk is not present in the drive, the program enters the while loop which asks user to insert the disk and continuously tries to open it, after the user has inserted the disk the program seems to run fine, however there is no data in the output file.I think it could be a...
2
448
by: slyphiad | last post by:
i'm kinda new at c++ so be patient ^_^ i was just wondering if u guys could help me to solve this problem that i had. i'm trying to create 5 sequential files using ofstream. this is what i did below: char filename = {"quest.01.cpp","quest.02.cpp","quest.03.cpp","quest.04.cpp","quest.05.cpp"};
2
1878
by: BCC | last post by:
Hi I have an application/project called HKDemo. In HKDemo.cpp, in the usual init stuff for the main class HKDemoApp, I can use the following code with no problems: ofstream out_file("test.txt", ios::out); try { out_file << "some stuff" << endl; } catch (...) { }
8
3380
by: ambar.shome | last post by:
Hi, We are working on Solaris SunOS 5.8. We are using ifstream of iostream namespace. The snippet is given below: #include <iostream.h> #include <fstream.h> boolean readFile() { char readStr;
5
18594
by: Squid Seven | last post by:
I'm trying to use a pointer to an ofstream object and having problems: ofstream *sessionFile = NULL; if( directory == "" ) sessionFile = new ofstream( fileName.c_str(), ios::out ); else {
7
7549
by: shawn | last post by:
Hi All, Am using MSVC6 compiler on a WinXP machine. Am trying to read a file using std::ofstream; the problem is that Tofstream.is_open() fails and Tifstream.rdstate() returns "2" which translates to "The system cannot find the file specified.". This is really weird because the said file am tring to read exists on the disk at the required location. SNIPPET:-
3
9936
by: magix | last post by:
Hi, I got following to savefile into Output.txt, but how can I specify it to be in specific folder/directory (not at the same directory as the executables? Currently, it will generate the output.txt under the same directory as the executables. std::stringstream stream; stream << "Output.txt" << std::flush; std::ofstream SaveFile(stream.str().c_str());
3
2000
by: Abubakar | last post by:
Hi, If I write the following code: ofstream f; f.open("c:\\hello.txt", ios::binary | ios::out); how do I check if the file is successfully opened and ready to write ? Should I do a f.is_open() check ?
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9023
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4366
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.