title: Writing Integers to a .txt file in c++
body: <p>I am new to C++ and want to write data(integers) on a <code>.txt</code> 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.</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;fstream&gt;
  using namespace std;
  
  int main ()
  {
      int i, x, y;
      ofstream myfile;
      myfile.open ("example1.txt");
      for (int j; j &lt; 3; j++)
      {
          myfile &lt;&lt; i ;
          myfile &lt;&lt; " " &lt;&lt; x;
          myfile &lt;&lt; " " &lt;&lt; y &lt;&lt; endl;
          i++;
          x = x + 2;
          y = x + 1;
      }
      myfile.close();
      return 0;
  }
  </code></pre>
  
  <p>Kindly point out the error or suggest a solution.</p>