I/O question

Ok simple question I hope. I read your tutorial on I/O streams and just had a couple questions between --> http://www.cplusplus.com/doc/tutorial/files/

 
	if (arbitrary.is_open()) 


and

 
	if (arbitrary.open()) 


I am taking a class right now and the teacher is wanting us to utilize the .fail function. However when I was reading your article I noticed the .is_open and in the tutorial it says it checks to see if the file is actually running, and returns a bool true value or false. I guess my basic question is does this do basically do the same thing as running and .fail function. Because both are able to have outputs saying the "program failed". Or am I reading this wrong and the is_open will just passively fail
Last edited on
closed account (SECMoG1T)
 
if (arbitrary.fail ()) /*is equivalent to */ if (! arbitrary.open ()) /* and*/ if (! arbitrary. is_open ())


Bur I would use them for different purpose

I would use fail () or open () to check if a file successfully opened
I would use is_open () in iterations e.g. on reading the file

1
2
while (infile.is_open ())
/// read the file 
Last edited on
so if (arbitrary.is_open()) /*is equivalent to */ arbitrary.open /*if there are no failures? */
Last edited on
closed account (SECMoG1T)
Yea
1
2
 if (arbitrary.is_open ())   /*and */ if (arbitrary.open ()) /// are equal 
        /// both return true if the file is open and false if the file isn't open  
I guess what I am cunfused on is how they both return false. do they just passively in the background do nothing or does one output have a different outcome?
Topic archived. No new replies allowed.