I m a new budding programmer.Is it possible for me to create a new header file of my own? Can anyone help me how to create my own header file in c++ with an example ?
Asked
Active
Viewed 1.1e+01k times
18
-
3possible duplicate of [How can I create C header files](http://stackoverflow.com/questions/2831361/how-can-i-create-c-header-files) – In silico Nov 16 '13 at 06:50
-
1See this webpage: http://www.learncpp.com/cpp-tutorial/19-header-files/ – Sid Nov 16 '13 at 06:50
2 Answers
36
Yes, of course you can, but before that you need to learn what header files are and how you can use them properly.
file: yourname.h
#ifndef YOUR_NAME_INCLUDE
#define YOUR_NAME_INCLUDE
/* Your function statement here */
#endif
yourname.cpp
#include <iostream.h>
#include "yourname.h"
/* Your function definition here */
main.cpp
#include <iostream.h>
#include "yourname.h"
/* Your function calling here */
To learn more about header files and include statements, click the link below.

Ashvin Sharma
- 563
- 1
- 5
- 24

Jefree Sujit
- 1,546
- 5
- 22
- 38
6
Yes, you can create your own header file.
- Kindly go through thinking in c++ by bruce eckel vol 1.
- Just to begin with, a header file is which has extension '.h'/'.hpp'
- These files have declaration of user defined data structures and interfaces such has class declaration, function prototypes and etc.
- After declaring and storing it into project folder. you need to include this file in .cpp/.c eg.:
file: myheader.h
#ifndef MYHEADER
#define MYHEADER
......
#endif
file: myclass.cpp
#include <iostream.h>
#include "myheader.h"

Ashutosh
- 169
- 7
-
is it necessary to write in capital: **MYHEADER** when the file named `myheader.h`? – Peyman Majidi Jun 27 '21 at 05:16