How to Add Header Files in Dev C++?
What are header files in C++?
One of the features provided by the C++ Standard Library for its users is header files.
The input-output stream is represented by a header file in the C++ program, which is used in conjunction with "cin" and "cout" functions. Macros, information type definitions, and capacity definitions are all contained in a header file.
In C++, a header file consists of:
- Function definitions
- Data type definitions
- Macros
These functionalities are provided by header files, which are imported into your program via the #include preprocessor command. The C++ compiler receives instructions from these preprocessor directives telling it that these files must be processed before compilation.
The header file, which stands for input and output stream and is used to display output using the "cout\\" function and accept input using the "cin>>" function, must be present in any C++ program.
There are Two categories of header files:
- Standard library files: We must import the files that the C/C++ compiler currently recognizes.
- User-defined header files: The "#include" command can be used to import these documents, which are defined and characterized by the user.
Different Header files present in C++:
- stdio.h: Uses the scanf() and printf() functions for input and output, respectively, to carry out input-output operations.
- iostream: The input-output is streamed using the cin and cout functions.
- string.h: This file contains functions for manipulating strings, including strcpy(), strlen(), strcmp(), and others.
- stdlib.h:The standard library header, stdlib.h, is utilized by functions such as calloc() and malloc(), which are used for dynamic memory allocation.
- Math.h: This library uses functions like sqrt(), log2(), round(), pow(), and more to carry out mathematical computations.
- Conio.h: Handles input and output functions for the console, including getch() and clrscr().
- iomanip.h: Provides access to functions that place in variables and limit decimal values, such as set() and setprecision().
- Signal.h: Signal handling operations like as raise() and signal() are carried out by signal.h.
- Stdarg.h: This file collects arguments, displays the variable-length argument list, and executes common argument functions like va_start() and va_arg().
- errno.h: This file handles error handling tasks by utilizing functions such as errno(), strerror(), and perror().
- fstream.h: Regulates what data is written into files as output and what data is read from files as input.
- Time.h: This file contains date-and-time-based functions, such as setdata() and getdata(), that can also be used to change the CPU time and system date.
- float.h: This adds portability to programs. It includes ANSI C-recommended platform-dependent constants such as radix and exponents.
- limits.h: It determines the various variable sorts' attributes. The macros described in this header limit the upsides of several variable types, such as long, int, and char. These cut-off points indicate the maximum value that an unsigned person can save; for example, 255 is the maximum value that a variable can save.
Adding Header files to Dev C++:
We can add headder files in C++ in 2 ways:
1. #incude<name>
2. #include “name”
Steps to add header files in dev c++:
Step 1: Make a new file and program the functionality of the header file in it.
Let the example code be:
void fibonacci(int n)
{
int first = 0, second = 1, next;
std::cout << "Fibonacci Series up to " << n << " terms:" << std::endl;
for (int i = 0; i < n; ++i) {
if (i <= 1)
next = i;
else {
next = first + second;
first = second;
second = next;
}
std::cout << next << " ";
}
std::cout << std::endl;
}
Step 2: Save this file with the Header files extension (.h,.hpp,.rh,.hh) in the current working folder.
![How to Add Header Files in Dev C++?/>
<!-- /wp:html -->
<!-- wp:paragraph -->
<p><strong>Step 3:</strong> Use the #include keyword to include the recently generated header file in the now-running code.</p>
<!-- /wp:paragraph -->
<!-- wp:quote -->
<blockquote class=](https://static.tutorialandexample.com/cpp/how-to-add-header-files-in-dev-cpp1.png)
Note: Always ensure that the header file(s) and the currently in-use functioning code are stored in the same folder.
Main code of the Fibonacci series is:
int main()
{
int num;
std::cout << "Enter the number of terms for Fibonacci series: ";
std::cin >> num;
fibonacci(num);
return 0;
}
The preset file iostream and the constructed file fibonacci() are the two header files included in the code. The initialization of two numbers occurs inside the main() block. The user enters data using the cin function, and output is shown on the screen using the cout function.
Step 4: Compile and Run
![How to Add Header Files in Dev C++?/>
<!-- /wp:html -->
<!-- wp:html -->
<div class=](https://static.tutorialandexample.com/cpp/how-to-add-header-files-in-dev-cpp2.png)