Thread: #please clear this up for me

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    95

    #please clear this up for me

    I'm not clear as to the purpose of these preproccer directives in all my header files
    #ifndef _FILENAME_HPP_
    #define _FILENAME_HPP_

    also is it neccary to include <iostream> in my header file if it is included in my main file?

  2. #2
    Unregistered
    Guest
    by using the #ifndef and #define, you will prevent the compiler from linking the header twice, which will cause you an error. sample:

    #ifndef _HELLO_H
    #define _HELLO_H

    #include <stdio.h>
    #include <iostream.h>

    int something;


    #endif

  3. #3
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    #ifndef _HELLO_H
    #define _HELLO_H

    // your code goes here...

    #endif


    this is a preprocessor directive that is used when a file Hello.h is included within another file....especially when Hello.h is used by many different files, the purpose of this is NOT to have multiple declarations of Hello.h......

    those statements mea: if ... hello.h is not yet defined within the program (or a file system) ....then define it (write it in)......at the end you need... #endif.....to end your if statement

    Regards,
    matheo917

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    Re: #please clear this up for me

    Originally posted by rip1968
    also is it neccary to include <iostream> in my header file if it is included in my main file?
    If you call a function from <iostream> anywhere in the *.cpp file associated with the header file, then yes you do need to include it.
    Last edited by jdinger; 05-04-2002 at 08:22 AM.

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    95
    Thanks to you all for clearing these points up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About clear(). Please help!
    By Antigloss in forum C++ Programming
    Replies: 12
    Last Post: 07-14-2005, 04:02 AM
  2. How to Clear in Visual C++
    By MyDestiny in forum Windows Programming
    Replies: 4
    Last Post: 03-16-2005, 10:40 PM
  3. How to Clear in Visual C++ 6.0
    By MyDestiny in forum Windows Programming
    Replies: 1
    Last Post: 03-16-2005, 11:57 AM
  4. Yet another clear screen thread :D
    By kermit in forum Linux Programming
    Replies: 2
    Last Post: 11-20-2003, 05:14 AM
  5. Using a button to clear a list box!
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 08-23-2002, 07:44 PM