Thread: Header files

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    51

    Header files

    Hi,

    I've done some searching on this site on header files but haven't got much luck...

    I was wondering how exactly header files work...
    Say for example, I want to create a simple header file to include with my code, what kind of coding do I need in the .h file...
    All i know is the command #include "myheader.h"..

    Can someone give me some more information on header files?
    Which is the master, which is the student?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    a header file can have variables, functions, classes, structs, includes, and stuff like that. for example, here is an sample main file:
    Code:
    #include "myHeader.h"
    
    int main(){
        func();
        cout << i;
        retun 0;
    }
    ok, heres the header:
    Code:
    #include <iostream.h>
    void func();
    int i;
    
    void func(){
       i = 15;
       return;
    }
    of course you can take out any part of this so you can have:
    Code:
    void func();
    int i;
    
    void func(){
       i = 15;
       return;
    }
    but youd have to include iostream.h somewhere.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    51
    Ah...ok, ... thanks for the reply
    Which is the master, which is the student?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. #include header files or .cpp files?
    By DoctorX in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2006, 12:21 PM
  3. classes and header files
    By Drake in forum C++ Programming
    Replies: 8
    Last Post: 11-30-2006, 07:12 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM