Question:

What are header files in c++?

by  |  earlier

0 LIKES UnLike

what are header files in C++? when is the correct time to use them?

 Tags:

   Report

3 ANSWERS


  1. header files define special functions in your program, and the correct time to use them is when you're gonna need one of those functions; i.e. cos, tan, and sin, I believe are in <cmath>


  2. Header files are just simple text files you wanna include in your program. It's like I simply copied and pasted whatever was in that file into my program.

    For example, if i have 35 functions in my program, and I don't want to have a big jumbled mess all over my code, i break it up into smaller header files. Usually I have one header per function and the name of the header is the same as the function.

    So let's say I have the function panda(). It's really long, and I don't want to jam up the main.cpp file.

    i just right the code as follows (assuming that panda.h includes said function)

    #include <iostream>

    #include "panda.h"/*keep in mind that there are quotes, not the pointy things*/

    int main(){

    //blah blah blah

    panda();

    return 0;

    }

  3. Header files most often contain function signatures and class declarations. If you are using any function to write text to the screen or get input, you will probably be using code that has already been written by someone else. In this case, your program needs to know how to use this code. The header files give the appropriate syntax and argument lists for each function that you may use like printf, sqrt, cout or anything that you didn't write yourself.

    You can also use headers to define your own classes and functions. If you want multiple source files to be able to use the same functions, you can declare them in a header and then just use #include to use the functions in the other source files.

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.