DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   Simple Varifacation please (http://www.daniweb.com/forums/thread160298.html)

clutchkiller Dec 1st, 2008 3:15 pm
Simple Varifacation please
 
I just wanted to make sure i am interperating code correctly when i write or read it when it comes to fstream.

when you say

ofstream example;

your basically making a keyword "example" to call different functions.
aka example.open()
or .close.

but, if i used example as the out put operator, i need a different name for ifstream.

So i could type

ifstream exampletwo;

And then use that "Keyword" to read from files that i write using the example keyword?

Does any of this make sense lol? Thanks

Narue Dec 1st, 2008 3:41 pm
Re: Simple Varifacation please
 
"Keyword" is a term already used to mean something else, so redefining it will only confuse you.

What you're doing is creating an variable of the ofstream class and calling it "example". You then invoke functions on that variable. Calling member functions can be confusing if you try to think about it too hard without knowing that
example.open ( "foo" );
essentially boils down to something like this:
ofstream_open ( example, "foo" );
The object.method() form of calling member functions is pretty much just syntactic sugar for a more low level function call. It's the same thing with overloaded operators. When you say
cout<< 12345;
, the compiler translates it into a member function call:
cout.operator<< ( 12345 );
Which is then in turn converted to a lower level function call:
ostream_operator<< ( cout, 12345 );
From here, everything you've learned about functions can be applied to make the world a bit more consistent. :)

clutchkiller Dec 1st, 2008 6:09 pm
Re: Simple Varifacation please
 
I get it. What you just said helped me peice it all together in my head. Thanks a lot!


All times are GMT -4. The time now is 5:43 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC