#include <iostream>
#include <fstream>
#include "stdafx.h"
using namespace std;
int main()
{
ofstream myfile;
myfile.open("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
I am trying out basic file handling in c++ using visual studio 2017, can't seem to use the class fstream
error - Severity Code Description Project File Line Suppression State Error C2065 'myfile': undeclared identifier CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 11
Error C2065 'ofstream': undeclared identifier CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 8
Error C2146 syntax error: missing ';' before identifier 'myfile' CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 8
Error C2065 'myfile': undeclared identifier CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 8
Error C2065 'myfile': undeclared identifier CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 9
Error C2228 left of '.open' must have class/struct/union CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 9
Error C2065 'myfile': undeclared identifier CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 10
Error C2228 left of '.close' must have class/struct/union CSV C:\Users\User\source\repos\CSV\CSV\CSV.cpp 11
what should I do ?
#include "stdafx.h"
– john