I am new to C++ and want to write data(integers) on a .txt
file. The data is in three or more columns that can be read later for further usage. I have created successfully a reading project but for the writing one the file is created but it is blank. I have tried code samples from multiple sites but is not helping.
I have to write results from three different equations as can be seen from the code.
#include<iostream>
#include<fstream>
using namespace std;
int main ()
{
int i, x, y;
ofstream myfile;
myfile.open ("example1.txt");
for (int j; j < 3; j++)
{
myfile << i ;
myfile << " " << x;
myfile << " " << y << endl;
i++;
x = x + 2;
y = x + 1;
}
myfile.close();
return 0;
}
Kindly point out the error or suggest a solution.