title: Outputting Values from a 2D Array to a Text File
body: <p>I am writing some C++ code and i currently have a function that reads in some numbers from a text file and stores them into a 2D array. I now need to output the same numbers i have stored into the 2D array back out into a new text file. I currently have some code in a function that can output the numbers however they are not in the same format as the input file. As you can see below.</p>
  
  <p>Input File Format (space between each number)</p>
  
  <pre><code>1 2 3 4 5 6 7 8 9
  2 3 4 5 6 7 8 9 1
  3 4 5 6 7 8 9 1 2
  4 5 6 7 8 9 1 2 3
  5 6 7 8 9 1 2 3 4
  6 7 8 9 1 2 3 4 5
  7 8 9 1 2 3 4 5 6
  8 9 1 2 3 4 5 6 7
  9 1 2 3 4 5 6 7 8
  </code></pre>
  
  <p>Output File Format Currently 
  <code>123456789234567891345678912456789123567891234678912345789123456891234567912345678</code> (this is all on one line)</p>
  
  <p>My function to read in from the text file.</p>
  
  <pre><code>void Grid::LoadGrid(const char filename[])
  {
      ifstream file(filename);
      for (int y = 0; y &lt; 9; y++) {
          for (int x = 0; x &lt; 9; x++)
          {           
              file &gt;&gt; m_grid[x][y];
          }
      }
      file.close();
  }
  </code></pre>
  
  <p>My function to read out to the text file. (m_grid is the 2D array)</p>
  
  <pre><code>void Grid::SaveGrid(const char filename[])
  {
      ofstream file(filename);
      for (int y = 0; y &lt; 9; y++) {
          for (int x = 0; x &lt; 9; x++)
          {
              file &lt;&lt; m_grid[x][y];
          }
      }
      file.close();
  }
  </code></pre>
  
  <p>If anyone can help me output it to the text file so it will appear the same as the input i'd be very grateful.</p>
  
  <p>Edit: Question has been answered.</p>