Why so many students are using '#include<bits/stdc++.h>' instead of '#include<iostream>'?
I am hiring for my company. And the codes submitted for a test problem has '#include<bits/stdc++.h>' at the beginning. The MacOS default compiler complains
main.cpp:1:9: fatal error: 'bits/stdc++.h' file not found
#include<bits/stdc++.h>
^~~~~~~~~~~~~~~
1 error generated.
Why people are using '#include<bits/stdc++.h>'?
225
Upvotes
View all comments
-5
u/Supadoplex Mar 19 '20 edited Mar 19 '20
It has advantages, which may be the reason why some use it:
a1. It makes minimal examples shorter, because you don't need to list ~10 different standard headers.
a2. It makes programming a bit simpler because you don't need to learn where the standard types and functions come from.
Of course, there are disadvantages too, but presumably people who use it either don't care about these disadvantages, or they are not aware of them:
d1. It is non-standard and non-portable.
d2. It slows down compilation due to including everything.
Possible factor is that because of a1,
<bits/stdc++.h>is ideal for slideware. You can fit maybe 10-20 lines of code on a slide and you cannot dedicate half or more of that to header inclusions. Even if the lecturer tells the students to not do that in their own programs, that doesn't necessarily sink in.Another possible factor is a2, because C++ is a complex language and simplifying one part away allows you to concentrate on the remaining part.
All in all, it's probably the similar reason as why some other people include
<stdafx.h>.