How do you make header files?

I'm not talking about just a text file with code, I mean
a header file containing functions C++ or any other header library has.
:) Hope you can help,
There is actually no intrinsic difference between the two, as far as how they are made. You write it in a text file, same as you do for your .cpp files. You just name them .h instead of .cpp.

What changes is what is usually placed in them. It is customary to place definitions of your classes, class members, functions etc in a header file. And the main bulk of application code will go in .cpp file/files. Oftentimes you will see headers containing only the definitions and an accompanying .cpp file with the same name as the header file containing the code for each of the defined functions.

If you have written a header file of your own, you can include it using either of these two formats:

#include "myheader.h"
#include <myheader.h> 

The first one will look for the file in the same directory as the file containing the #include , while the second one (which you likely see most often for standard library headers) looks for the header in predefined directories.

So if you made a header file of your own, and wanted to use the second #include form using < > , you would have to define it's location before compiling your project -- otherwise you could use the first form using double quotes after making sure that the header is in the same directory as the file containing the #include "myheader.h" .
Last edited on
Topic archived. No new replies allowed.