Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should I not #include <bits/stdc++.h>?

I posted a question with my code whose only #include directive was the following:

#include <bits/stdc++.h> 

My teacher told me to do this, but in the comments section I was informed that I shouldn't.

Why?

like image 478
Lightness Races in Orbit Avatar asked Aug 04 '15 17:08

Lightness Races in Orbit


People also ask

Why should not I or why should I not?

So, when we use shouldn't I instead of should I not, we mean so to say that things in fact were not wrong, but perhaps unnecessary. The same I meant saying that when I pronounce variants where "not" put after pronoun it sounds more serious and solid, than when we use shouldn't.

Why would I vs Why should I?

"Why would I X" is asking for the reasons that would force you, lead you, or make you do X. "Why should I X" is asking for the reasons that you would voluntarily choose to do X. A speaker/writer may not know that someone actually has or doesn't have a choice in something, so they may use the "improper" word.

Why can't I or why can I not?

Can't is a contraction of cannot, and it's best suited for informal writing. In formal writing and where contractions are frowned upon, use cannot. It is possible to write can not, but you generally find it only as part of some other construction, such as “not only . . . but also.”

Should we or should we not?

-- Correct, we should not. In three out of four of these cases should is being used to express obligation or what is the correct action. Should we not. is the only case where the meaning is shifting to the conditional sense of the word should.


1 Answers

Including <bits/stdc++.h> appears to be an increasingly common thing to see on Stack Overflow, perhaps something newly added to a national curriculum in the current academic year.

I imagine the advantages are vaguely given thus:

  • You only need write one #include line.
  • You do not need to look up which standard header everything is in.

Unfortunately, this is a lazy hack, naming a GCC internal header directly instead of individual standard headers like <string>, <iostream> and <vector>. It ruins portability and fosters terrible habits.

The disadvantages include:

  • It will probably only work on that compiler.
  • You have no idea what it'll do when you use it, because its contents are not set by a standard.
  • Even just upgrading your compiler to its own next version may break your program.
  • Every single standard header must be parsed and compiled along with your source code, which is slow and results in a bulky executable under certain compilation settings.

Don't do it!


More information:

  • #include <bits/stdc++.h> with visual studio does not compile
  • How does #include <bits/stdc++.h> work in C++?

Example of why Quora is bad:

  • Is it good practice to use #include <bits/stdc++.h> in programming contests instead of listing a lot of includes?
like image 174
Lightness Races in Orbit Avatar answered Sep 26 '22 03:09

Lightness Races in Orbit