Preprocessor Directives

This is a discussion on Preprocessor Directives within the C++ Programming forums, part of the General Programming Boards category; HELLO!!!!!, I am a little confused about when to use a specific preprocessor directive. I know that each directive contains ...

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    Question Preprocessor Directives

    HELLO!!!!!, I am a little confused about when to use a specific preprocessor directive. I know that each directive contains different reserved words and library identifiers, but how do you know when to use them? Since I don't know much about this, I have been sticking to <iostream> and <iomanip>, but I don't even know what they mean. Choosing a directive is like a guess and check game with me. PLEASE HELP. Thanks.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  2. #2
    Amateur Programmer
    Join Date
    Nov 2003
    Posts
    11
    The #include directive is for using certain header files in your program. For example std::cout is found in <iostream> fstreams are found in <fstream> to use the std:string you have to call <string> etc...

    The #define directive let's you make macros such as #define COUT std::cout which would allow you to do COUT << "Hello, World!"; instead of std::cout...

    Try here for more info.

  3. #3
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    <iostream> is a header file, not a preprocessor directive. Preprocessor directives are commands preceeded with a '#' that are executed before the rest of your code....and even tell the compiler HOW to compile.

    #define creates a global "macro" function or constant without a type.

    #ifdef, #ifndef, respectively check to see if something is defined, or isn't....from there, you can have code execute before the rest of your code...which again...can tell your compiler HOW to compile.

    There are many more, but you can easily just Google them.

  4. #4
    Deo
    Deo is offline
    Registered User
    Join Date
    May 2005
    Posts
    73

    Thumbs up

    <iostream> = Input/Output Streams. [cout; cin; etc..]
    <iomanip> = Input/Output Manipulation. [Text formatting]
    ...
    <conio> = Console Input/Output

    When I first started I just included them because my instructor said so! I often included stuff I didn't even use in my project, but if you find out what they mean it makes things easier.

    MSDN documentation helped me immensely as I could actually see what these files were.

    Code:
    <iostream>
    namespace std 
    {
        extern istream cin;
        extern ostream cout;
        extern ostream cerr;
        extern ostream clog;
        extern wistream wcin;
        extern wostream wcout;
        extern wostream wcerr;
        extern wostream wclog;
    };
    Last edited by Deo; 05-29-2005 at 10:16 AM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21