<bits/stdc++.h> as header file in C++

In this article, we are going to see how useful <bits/stdc++.h> is as a header file for competitive programing?
By Radib Kar Last updated : December 11, 2023

C++ <bits/stdc++.h> header file

It's the header file that includes every header files, i.e., links every header file to our program.

Adding <bits/stdc++.h> header file to code

The following code chunk is enough to include every header file needed to be linked in the program.

#include <bits/stdc++.h>
using namespace std;

Like you don't need to put your time on writing & finding each header file to be mentioned, instead, just add this piece of code chunk.

Complexity Time

It's true that including <bits/stdc++.h>, makes the program size larger and increase the complexity time. Also it's not part of standard library and can only be used in gcc compiler. Other compilers like MSVC(Microsoft Visual C++) don't have this header.

Though <bits/stdc++.h> has such pitfalls, we are not at all bothered by this, since our only focus is on competitive coding context, where we are only concerned about run time complexity, not compile time. Also gcc is used everywhere. Thus using <bits/stdc++.h> is a very efficient coding style for solving interview coding problems.

Important Note

One more thing can be very tricky is when we have functional problems to solve. There may be case we have a functional problem, where we need to write the function only & rest of the code is already given (can't be modified). In such case, we may need to use STL, but so such header file is included in the given code for STL. In such case, it might seem that, we can't use STL here & we need to take any other way, which is not at all efficient. If you think so, wait a minute!!!


You can add #include <bits/stdc++.h> anywhere in the code, since it's an ANCI MACRO. That's why just write #include <bits/stdc++.h> before where you start using STL. (Before the function). That's all.

For example check all my codes (Radib Kar's articles), as I use it everywhere!!

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.