c++portabilityturbo-c++c++-faqimplementation-defined-behavior

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?


Solution

  • 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:

    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:

    Don't do it!


    More information:

    Example of why Quora is bad: