I am in Visual Studio and am getting 'ifstream undeclared identifier' with this code (same for ofstream)
#include <iostream>
#include <iomanip>
#include <fstream>
void main()
{
ifstream infile("file.txt");
ofstream outfile("out.txt");
}
do I need to include something else?
You need to scope it. Use using namespace std;
or preface ifstream
and ostream
with std::
For example, std::ifstream
Currently, the compiler does not know where these structures are defined (since they are declared/defined within the std
namespace). This is why you need to scope your structures/functions in this case.
You need to reference the standard namespace (std). Try this:
#include <iostream>
#include <iomanip>
#include <fstream>
void main()
{
std::ifstream infile("file.txt");
std::ofstream outfile("out.txt");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With