#include <bits/stdc++.h>
If I put the above line at the top of my program.cpp
file, it gives me the following error message:
cannot open source file "bits/stdc++.h"
How can I fix this?
#include <bits/stdc++.h>
If I put the above line at the top of my program.cpp
file, it gives me the following error message:
cannot open source file "bits/stdc++.h"
How can I fix this?
It's an internal GCC header file. There is no guarantee that it will work anywhere else; even using it with GCC itself is poor practice for many reasons. Do not use it, ever.
How can I fix this?
Include those standard headers which you actually need. For example, if you need std::cout
, then include <iostream>
. If you need std::string
, then include <string>
. If you need std::ifstream
, then include <fstream>
.
As those are standard headers, they are guaranteed to work everywhere.
cppreference.com is a good free online source to find out which headers are needed for which component of the standard library. Let's take a non-obvious one, like std::ifstream
. You just search for that name and you'll find http://en.cppreference.com/w/cpp/io/basic_ifstream. There, it says:
Defined in header
<fstream>
That is not a Standard C++ header file, and Visual C++ does not implement it. You should not use it even if the compiler you are using does implement it, as it makes your code immediately non-portable, possibly even between different versions of the same compiler.