Using bits/stdc++.h header in C++
Hey, guys today we are going to learn about <bits/stdc++.h> header file in C++. Before starting with <bits/stdc++.h>header file , lets discuss header files in brief.
Header Files in C++
Header files store function declarations and macro definitions that are to be shared between different files. They are included by the preprocessor directives #include and usually have .h extension. Its syntax is:
Header files are of 2 types:
- Standard library header files: These stores the basic functions required to create and run a program successfully. Example: <iostream> stores the basic input/output streams without which we can’t take input or print anything. Other common header files include <stdio.h>,<string.h>,<stdlib.h>,<math.h>,<conio.h>,<process.h>,<time.h> etc
- User-defined header files: These are created by the user and contains all global variables, macro definition, global functions’ declarations which are shared between different compilations unit. These header files are useful in integrating different programs to create one.
<bits/stdc++.h> header file in C++
<bits/stdc++.h> header file is collection of all standard library header files. In other words, we can say that is all in one standard library. It is mostly used in coding competitions where one’s rank is time-dependent and thus a programmer does not want to waste his/her time writing #include statement for different header files. Moreover, if a programmer is using <bits/stdc++.h> he/she need not remember which function is contained in which header file. It increases the program size and compilation time as it includes many header files which are not required by the program which is not a good practice as a software programmer. It can be included as shown:
After knowing the above advantages of <bits/stdc++.h> one might think to use <bits/stdc++.h> instead of using standard library header files. However one must consider the following disadvantages of using <bits/stdc++> :
- <bits/stdc++.h> is not a standard header file of C++ and thus compiling a program with compilers other than GCC may fail.
- As <bits/stdc++.h> is not part of standard C++ library, it is non portable.
- Including <bits/stdc++.h> includes all the C++ standard header files out of which many are not required for a program which results in an increase of program size and thus increase in compilation time.
- If using <bits/stdc++.h> the compiler actually reads and parse every included header file recursively every time program is compiled.