Skip to content

How to add a header file in Dev C++?

  • by
  • 6 min read

Dev-C++ is a free IDE for programming in C/C++, created by Bloodshed programming. With Dev-C++, you can compose Windows or control centre based C/C++ programs effectively; you can even make an installer for your application.

It runs exclusively on Windows; the Linux port does not exist anymore.

In this article, we will see how to create and add header files in Dev C++.

Also read: What is the difference between C++ and Java?


Header files in Dev C++

The C++ program has a header file that represents the input-output stream and is used with the assistance of “cin” and “cout” separately.

A header record contains Capacity definitions, Information type definitions and Macros.

There are two kinds of header documents:

  • Standard library files: Files which are now accessible in C/C++ compiler, we definitely need to import them.
  • User-defined header files: These documents are characterised and defined by the user and can be imported by using “#include”.

Here is a list of the standard header files that are already predefined and available for use.

  • stdio.h: Performs input-output functions using the scanf() and printf() functions for input and output, respectively.
  • iostream: The functions cin and cout are used to stream the input-output.
  • string.h: Used for string manipulation using different functions like strcpy(), strlen(), strcmp() and others.
  • stdlib.h: This is the standard library header used for functions like the dynamic memory allocation using malloc() and calloc().
  • math.h: Performs mathematical operations by functions like pow(), sqrt(), log2(), round() and more.
  • conio.h: Performs the console input and output functions like getch(), clrscr() and others.
  • iomanip.h: Accesses functions like the set() and setprecision() which limit decimal value and places in variables.
  • signal.h: Performs signal handling functions like the raise() and signal().
  • stdarg.h: Performs standard argument functions like va_start() and va_arg() and also fetches arguments and indicates the variable-length argument list.
  • errno.h: Using functions like errno(), strerror(), and perror(), it performs error handling operations.
  • fstream.h: Controls the data to be read from files as the input and the data to be written as the output into the file.
  • time.h: Performs functions based on date and time, that can also modify the system date and CPU time like setdata() and getdata().
  • float.h: This makes programs more portable. It contains platform-dependent constants like exponents, radix and others that were proposed by the ANSI C.
  • limits.h: It decides different properties of the different variable sorts. The macros characterised in this header, restricts the upsides of different variable sorts like char, int, and long. These cut-off points determine that a variable can’t store any worth past these cut-off points, for instance an unsigned person can save to a most extreme worth of 255.

Also read: Python vs Java vs C/C++: Key differences and Pros-Cons.


How to add header files in Dev C++?

There are two methods to add header files for C++ programming. These header files can be user-defined as well as predefined. The #include keyword is an essential part of adding header files to any program.

Method 1: #include <filename>

Including the header filename within angular brackets is the most common method of adding a header file to the code. For C++, the header filename need not have the .h extension, but for C, the .h extension is necessary.

How to add a header file in Dev C++?

The cout function is an output function predefined in the iostream header file. The header file iostream is enclosed in angular brackets, and when the cout function is called, the output “These angular brackets work!” is displayed on the output screen.

Method 2: #include “filename”

The second method for adding header files is enclosing them in double-quotes. Like with the angular brackets, the .h extension is necessary for C, while it isn’t for C++.

How to add a header file in Dev C++?

Here, the header file iostream is enclosed in double-quotes. The cout function is an output function predefined in the iostream header file which, when called, the output “The double quotes work!” is displayed on the output screen.

Also read: Top 10 Programming Languages in 2020.


How to create a header file in Dev C++?

Multiple predefined header files are already present, but if a function needs to be repeatedly called, we can create our own header files with a specific given functionality. This helps keep the code clean and more understandable.

Step 1: Create a New file and code the header file functionality in it.

Shown below is the code for performing the addition of two numbers.

int sum_of_numbers (int a, int b)
{
	int sum = 0;
	sum = a+b;
	return sum;
} 

Step 2: Save this file in the current working folder with the Header files extension — .h, .hpp, .rh, .hh.

The standard save as type is generally cpp, so ensure to change it as a header file.

How to add a header file in Dev C++?

Step 3: Add the newly created header file to the current working code using the #include keyword.

Always make sure that the current working code and the header file(s) are saved in the same folder.

Below is the main code for performing the addition of two numbers.

#include "iostream"
#include "sum_of_nos_header.h"

using namespace std;

int main()
{
	int num1, num2;
	cout<<"Enter a number: ";
	cin>>num1;
	cout<<"Enter another number: ";
	cin>>num2;
	cout<<"The sum is: " 
		<< sum_of_numbers(num1,num2)
		<< endl;
	return 0;
} 

The code includes two header files, the predefined file iostream and the created file sum_of_nos_header. Inside the main() block, two integers are initialised. The cin function takes input from the user, while cout is used to give output on the screen.

Step 4: Compile and run.

How to add a header file in Dev C++?

This is how header files can be created and added in Dev C++.

Also read: What’s the difference between C and C++?

nv-author-image

Ishita Maheshwari

A creative nerd, TT player, an avid reader, and an engineering student.

  • Mirsaeid says:

    Hi dear friend,
    I have a question about header file. I have worked with C language two decades ago. For finding header file of a function was used to apply Ctl+F1, but in Dev C++ which is a short cut to do so?
    Second question: What is the relevant function for gotoxy(x,y) in Dev C++ and what is its header file?

  • >