ok, i know im asking a lot, but would anyone be able to explain how functions work, an example would be great, or atleast a good tutorial, i've read the one on this site atleast 6 times thanks
-edit: in fact im reading it right now
ok, i know im asking a lot, but would anyone be able to explain how functions work, an example would be great, or atleast a good tutorial, i've read the one on this site atleast 6 times thanks
-edit: in fact im reading it right now
well i understand functions, just classes confuse the hell out of me
thanks, now would you recomend i read the functions one first, even though i have a good grip on them? or should i go straight to classes?
I'm probably not the best person to ask. I just started on C++. But from what I know I would look over the functions, that is used to wrtite the methods for your classes. I think you should understand how functions work fairly well though.
Good luck.
Everything is relative...
definitely functions first. because, well, what's a class without functions? well, just a structure. (don't worry about structures, if you learn classes you'll understand structures).
"What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)
ok, thanks
in all of the examples on the funtion page they use the header
fstream.h.... what is this? why dont they use iostream?
ANSI C++ Headers have no .h extension. Read: http://www.cplusplus.com/doc/ansi/hfiles.html for more info. fstream in particular contains a file I/O class which inherits from the standard console iostream classes (used in plain console I/O). I/O stands for input/output.Code:#include <fstream>
i know they dont have any .h headers, but this uses the header fstream.h and im sure it will work the same if it was just fstream, i was just wondering why they use fstream instead of iostream
Last edited by sreetvert83; 08-28-2005 at 09:04 AM.
Because iostream has different functions built in from fstream. Iostream contains things such as cout and cin, whearas fstream is for file I/O.
so, i should only use fstream if i want to do file i/o otherwise just use iostream right?
<ChrisFarley>That's correct!</ChrisFarley>
Uh, you can use more than one header file. Use iostream if you use cin or cout anywhere, and use fstream if you're using file I/O. Example:
Yes, I am very unsure about things sometimes. :P Suffice to say that if you use fstream, you'll probably want iostream.Code:#include <iostream> #include <fstream> #include <string> //Stuff related to the datatype "string" using namespace std; int main() { string a; a = something; cout << a; //Iostream is needed for cout to work. ofstream b("example.txt") //Fstream is needed for this to work. b << a: //I know fstream is probably needed for this, but I'm not sure if iostream is, since you don't have "cout" involved... //Then again, there is the << operator, so I'd say both headers are needed here. }
Last edited by linkofazeroth; 08-28-2005 at 10:05 AM.