Results 1 to 5 of 5

Thread: #include

  1. #1
    Guest
    What is this line for? What is contained in it? Like, are there built functions?

    Code:
    #include <iostream.h>
    And where is iostream.h located? Is it built into C++ or is it a separate file?


  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    A header file contains definitions of function prototypes and various constants. The prototypes are for the compiler to do its type-checking, but if there's no matching .lib file, the linker whinges at you.

    The iostream.h file contains input/output stream support, which is basically cout, cin, and that lot.

    The header files are usually stored in a folder called "include" (surprisingly enough). Look under your VC folder, and it should be there.

    Note the important distinction though:
    Code:
    #include <iostream.h>
    // is not
    #include "iostream.h"
    If it's enclosed in angle-brackets, it begins searching for the include file in the system includes folder (mentioned earlier). If it's in quotes, it begins searching in the current source folder.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Guest

    A few things..

    Say I make a file, do I need to include this .h files with it? And are these just the basics? There are many more out there on the C++ programming sites? And last thing (for now), you seem to be a C++ expert, parksie, how long did it take you to learn and what have you made in C++?

  4. #4
    Lively Member
    Join Date
    Aug 2000
    Location
    quebec
    Posts
    81

    Cool

    You include any file that contains defs of classes, functions, constants etc. that you want to use in your app.

    Here's how includes basically work:

    Ex.
    Code:
    //in file my.h
    #ifndef MY_H
    #define MY_H
    
    #include <windows.h>
    #include <whatever.h>
    
    // some function prototypes
    char* getPath(char* fileName);
    int addA_B(int a, int b);
    // class prototype
    class myClass : public
    {
    //  ....
    };
    class automobile : public
    {
    //...full class definition...
    };
    // end my.h
    #endif
    Then in my.cpp you would include 'my.h' but not 'windows.h' etc.
    because they were included in my.h and therefore will now
    be in my.cpp - includes are accumulative.

    So if you have another source file in your proj. you can do this:
    Code:
    #ifndef MY_H
      #include <my.h>
    #endif
    which will ensure that you only include my.h if it hasn't already been included.

    If you need to use some specific API for example a common control you would do

    #include <commctrl> // don't need the .h in VC++

    Anyway a lot more could be said.

    have fun
    C/C++,Delphi,VB6,Java,PB (blech!),ASP,JSP,SQL...bla bla bla and bla
    I love deadlines. I like the whooshing sound they make as they fly by.
    —Douglas Adams

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What you include depends on what you want to use. Basically, these are the standard ones you'll see the most. Note that some are part of the Standard C++ Library, and some are part of the Standard C Library. The C++ headers have no .h extension, although they're headers.

    Standard C++ Library
    --------------------------
    iostream - Input/Output stream support
    string - string class
    vector - Dynamic arrays

    Standard C Library
    --------------------------
    stdio.h - I/O
    stdlib.h - Various useful functions
    math.h - Maths functions
    string.h - Functions to manipulate strings in char array form

    The C functions can also be used from C++, too. Check in the documentation for each function to see which headers you need.

    It took me about 5 years to get confident with C, and I've been using C++ for the past 2 years (7 years total).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width