Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Why You Should Not #include



The <bits/stdc++.h> is a header file that includes all the standard C++ library. It is used during coding contests, as it helps in saving time while solving the problem since programmers do not have to remember all the header files. In the software engineering approach, we should reduce the use of this header file, as it includes lots of files, and sometimes that may not be required in the program. So it may increase the compile time.

In this article, we are going to discuss why we should not use the <bits/stdc++.h> header file in C++.

Disadvantages of using <bits/stdc++.h>

The disadvantages of using <bits/stdc++.h> header file is mentioned below:

  • The <bits/stdc++.h> is not a standard header file of the GNU C++ library. So, some compilers may fail to compile the source code with this header file.
  • Using <bits/stdc++.h> may require a longer time to compile the given code.
  • Since this is not a part of the standard C++ library, it is non-portable and should be avoided.
  • For this header file, every time the compiler tries to import the headers recursively, every time the code is compiled.

Comparing Compile Time of Programs

We have given two example codes below. The first example uses the <iostream> header while the second example uses the <bits/stdc++.h> header. Observe their compile time:

Example 1

In this example, we are printing the 'Hello World' program. We are using the <iostream> header. Try running it in your compiler and observe the compile time. The compilation time for this code will be < 1.5 seconds.

#include<iostream>
using namespace std;

int main()
{
    cout<<"Hello World";

    return 0;
}

The output of the above code is as follows:

Hello World

Example 2

In this example, we are printing the 'Hello World' program. We are using the <bits/stdc++.h> header. Try running it in your compiler and observe the compile time. The compilation time for this code reaches up to 3.5 seconds.

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

int main()
{
    cout<<"Hello World";

    return 0;
}

The output of the above code is as follows:

Hello World
Updated on: 2025-05-20T13:30:05+05:30

171 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements