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

"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. :)

I get it. What you just said helped me peice it all together in my head. Thanks a lot!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.