Thread: classes

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    176

    classes

    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

  2. #2
    Registered User Boomba's Avatar
    Join Date
    Jun 2003
    Posts
    89
    you wanna know how functions or classes work or both?

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    well i understand functions, just classes confuse the hell out of me

  4. #4
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Try this for functions, and this for classes.
    Also, if you know C I used this site to understand C++ better.
    Everything is relative...

  5. #5
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    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?

  6. #6
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    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...

  7. #7
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    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)

  8. #8
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    ok, thanks

  9. #9
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    in all of the examples on the funtion page they use the header
    fstream.h.... what is this? why dont they use iostream?

  10. #10
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Code:
    #include <fstream>
    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.

  11. #11
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    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.

  12. #12
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    Because iostream has different functions built in from fstream. Iostream contains things such as cout and cin, whearas fstream is for file I/O.

  13. #13
    Registered User
    Join Date
    Mar 2003
    Posts
    176
    so, i should only use fstream if i want to do file i/o otherwise just use iostream right?

  14. #14
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    <ChrisFarley>That's correct!</ChrisFarley>

  15. #15
    Registered User
    Join Date
    Aug 2005
    Posts
    91
    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:

    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.
    }
    Yes, I am very unsure about things sometimes. :P Suffice to say that if you use fstream, you'll probably want iostream.
    Last edited by linkofazeroth; 08-28-2005 at 10:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM