I have seen recently that #include <bits/stdc++.h>
includes every standard library and STL include file. When I try to compile the following code segment with Visual Studio 2013, it prints an error C1083: Cannot open include file: 'bits/stdc++.h': No such file or directory
. But it works perfectly fine with Code::blocks. Is there any way to avoid this error?
#include <bits/stdc++.h>
using namespace std;
int main()
{
}
I saw in some post that
... the header file is not part of the C++ standard, is therefore non-portable, and should be avoided. ...
But I think the file is helpful in contest programming.
Is there any way to avoid this error?
Yes: don't use non-standard header files that are only provided by GCC and not Microsoft's compiler.
There are a number of headers that the C++ standard requires every compiler to provide, such as <iostream>
and <string>
. But a particular compiler's implementation of those headers may rely on other non-standard headers that are also shipped with that compiler, and <bits/stdc++.h>
is one of those.
Think of the standard headers (e.g. <iostream>
) as a "public" interface, and compiler-specific stuff (like everything in bits/
) as the "private" implementation. You shouldn't rely on compiler-specific implementation details if you want your program to be portable to other compilers — or even future versions of the same compiler.
If you want a header that includes all the standard headers, it's easy enough to write your own.