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/stilgarpl Mar 19 '20

Some IDE are including those headers automatically if you are not careful. Clion does it.

17

u/a_false_vacuum Mar 19 '20

CLion doesn't care if the header file should be avoided. It will happily suggest something old like conio.h. While it's a useful help, you should always be careful about accepting the suggestions for adding headers.

Although a new C++ in Clion will start with iostreams. It doesn't add the headerfiles mentioned by OP in a new project by default.

1

u/sephirothbahamut Mar 19 '20

if i'm on windows i don't mind including conio.h, using a _getch(); for a "press any key to continue" feels way better than char c; cin >> c;

3

u/CubbiMew cppreference | finance | realtime in the past Mar 19 '20

When is it literally ever useful? Visual Studio does that automatically when you run a program (via Ctrl-F5)

4

u/sephirothbahamut Mar 19 '20

anytime you're writing a small command line utility and you want the user to be able to read something before going on. makes things quicker than having to input a valid character followed by enter if you simply want a "press any key to continue" thing, or lets you have a quick y/n choice without enter.

I just find it convenient