r/cpp • • Mar 19 '20

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

163 comments sorted by

View all comments

12

u/vibeTechr Mar 19 '20

bits/stdc++.h is a big header file that includes a lot of other headers, as the name suggests, from the standard library. GCC comes with that file, but MacOS has CLang as default compiler, and CLang doesn't have it (I don't know if you can add it or something) so it complains. Most of the time you can just switch it with iostream, but you might need also to include vectors or lists or other components of the standard library, depending on the project.

6

u/jangid Mar 19 '20

But is this in standards? The name “stdc++.h” is misleading if it isn’t.

5

u/HKei Mar 19 '20

No, the stdc++ refers to libstdc++, which is the name of the standard library implementation that gcc is using. This is opposed to libc++ which is the default for clang (at least on OSX, I think it's actually using libstdc++ by default on linux) or whatever Microsofts implementation is called.

4

u/STL MSVC STL Dev Mar 19 '20

I call it MSVC's STL or microsoft/STL.

1

u/FrankHB1989 Mar 20 '20

I'd protested. Too many unnecessary confusions are already spread here. And this time, even by the endorsed acronym of your name... :-(

... Does WG21 people still respect teachability at all?

1

u/bumblebritches57 Ocassionally Clang Apr 13 '20

STL is his initials.