+ 17

How to create user-defined header files?

16th Dec 2017, 5:46 PM
Abhishek Tandon
Abhishek Tandon - avatar
6 ответов
+ 11
What is a namespace? and can we use the same method in C language too??
17th Dec 2017, 5:22 AM
Abhishek Tandon
Abhishek Tandon - avatar
+ 9
inside your header file you can have several sections and you have to name these sections even if there is only one section. Each section in header file is called a namespace. I don't know about C.
17th Dec 2017, 5:33 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 8
In C++, you can follow these steps to create a header file: step1: create a new file like myheader.h step2: include necessary header files step3: create a namespace as follows namespace mynamespace{ codes for your free functions ... } step4: add some functions inside your namespace. step5: add more namespaces if you need. now you can include this header file in your program and use its functions.
17th Dec 2017, 4:17 AM
Vahid Shirbisheh
Vahid Shirbisheh - avatar
+ 6
Thanks Dorra
20th Dec 2017, 3:39 PM
Abhishek Tandon
Abhishek Tandon - avatar
+ 5
In the C language you can create a header file with extension (.h) in which you put all your functions and then in the main file with extension (.c) you put the name of the header file between " " and not between < > as the standard header files. example: #include <stdio.h> // standard header file #include "function.h"// user-defined header file ps : namespace in c++ language is the same stdio.h in c language and it's the header file which contains the input and output standard functions.
20th Dec 2017, 3:33 PM
Dorra Lamouchi
Dorra Lamouchi - avatar
+ 2
I believe only C derived languages support header files. You can read up in C languages with this app. But simply put, header files just contain prototypes functions for the related class and helps for compiling. Hence, just define your own class.
16th Dec 2017, 6:27 PM
H Chiang