What's best?
if ( File.is_open() ) or
if (! File.fail() )
What I mean is, do these functions do more then the obvius which I should know about hwne chusing.
I'm asking because fail() is const and is_open isn't.
What's best?
if ( File.is_open() ) or
if (! File.fail() )
What I mean is, do these functions do more then the obvius which I should know about hwne chusing.
I'm asking because fail() is const and is_open isn't.
Last edited by Zahl; 10-19-2002 at 07:37 AM.
Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something
well in your case may be not.. but conside a program where you have to check if a file is opened... So here u use the 2nd one and the fail one is used to see if a file failed to open...
Sounds like the same thing.
Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something
So File.is_open() == !File.fail() ???
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
no they are not the same in the context i have used them.... See i write a program to check the files that are currently opened by the user.... and here i would try to open each file and check if it failed.. I would just like to check if it is opened.....
I always write like this:
Code:ifstream fin("file.txt"); if (fin) { ... }
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
hmm... didn't know you could do that... what kind of overloated operater have they used to do that?
Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something
good question. I have wondered that myself. Is it something like overloading "if" or "!" ?
~Inquirer
Compilers:
GCC on Red Hat 8.1 (Primary)
GCC on Mac OS X 10.2.4 (Secondary)
Others:
MinGW on XP
Not too sure...but I think it may be operator void*() which returns NULL if the failbit is setOriginally posted by Inquirer
good question. I have wondered that myself. Is it something like overloading "if" or "!" ?
~Inquirer
but void functions doesn't return anything. That's the point about void.
Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something
(void) != (void*)Originally posted by Zahl
but void functions doesn't return anything. That's the point about void.
why doesn't it just return *, and doesn't * mean that it's somekind of pointer... well then a pointer to what.
String * or Char * or int * or...
Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something
To answer the OP's question, I prefer to be explicit in what I want so there is no confusion such as in this thread.
-PreludeCode:std::ifstream input_file ( "something.ext" ); if ( input_file.is_open() ) { // Work with the file. } else { // Report the error and handle }
My best code is written with the delete key.
Hey Prelude, maybe you, too, could ansver a question I maid two days ago here http://cboard.cprogramming.com/showt...threadid=26709 but never got an ansver on.
Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
Hell I might even learn something