Open In App

<bits/stdc++.h> in C++

It is basically a header file that includes every standard library. In programming contests, using this file is a good idea, when you want to reduce the time wasted in doing chores; especially when your rank is time sensitive. 
In programming contests, people do focus more on finding the algorithm to solve a problem than on software engineering. From, software engineering perspective, it is a good idea to minimize the include. If you use it actually includes a lot of files, which your program may not need, thus increases both compile time and program size unnecessarily. 
Disadvantages of bits/stdc++ 
 

Advantages of bits/stdc++ 
 



Example : 

For example to use sqrt( ) function, in <bits/stdc++.h> header file we need not have to write <cmath> header file in the code.






#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
    cout << sqrt(25);
    return 0;
}
 
//Compilation time 0.005s
//Code submitted by Susobhan AKhuli

Output
5

But if we use <iostream> header file, we have to write <cmath> header file to run the sqrt( ) function otherwise compiler shows that ‘sqrt’ was not declared in this scope.




#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
 
    cout << sqrt(25);
    return 0;
}
 
//Compilation time 0.003s
//Code submitted by Susobhan AKhuli

Output
5

So, the user can either use it and save the time of writing every include or save the compilation time by not using it and writing necessary header files. 

 

 


Article Tags :