title: Trying to implement my own << and >> streaming operators to operate on my Grid object
body: <p>My task is to overload my own "&lt;&lt;" and ">>" streaming operators to read and write values from and into my Grid. I am not sure how to implement this with my SaveGrid and LoadGrid. I've read multiple tutorials on overloading operators and this is what I got so far.</p>
  
  <p>I have already implemented friends of the class but I am not sure how to implement them in my grid.cpp. </p>
  
  <pre><code>friend ostream&amp; operator&lt;&lt;(ostream&amp; out, Grid&amp; grid);
  friend istream&amp; operator&gt;&gt;(istream&amp; in, Grid&amp; grid);
  </code></pre>
  
  <p>Looking for some suggestions on how I can implement this so I can read in and out with my existing methods using my overloaded operators with something like cout &lt;&lt; grid and cin >> grid, I apologise that I have not articulated this very well but any advice at all is appreciated.</p>
  
  <p><strong>Grid.cpp</strong></p>
  
  <pre><code>     #include "Grid.h"
          #include&lt;iostream&gt;
          #include&lt;fstream&gt;
          using namespace std;
  
      void Grid::LoadGrid(const char filename[])
      {
          ifstream newStream;
          newStream.open(filename);
  
          for (int y = 0; y &lt; 9; y++)
          {
              for (int x = 0; x &lt; 9; x++)
              {
                  newStream &gt;&gt; m_grid[y][x];
              }
          }
  
  
      }
  
  
  
      void Grid::SaveGrid(const char filename[]) 
      {
          ofstream newStreamOut(filename);
  
          for (int y = 0; y &lt; 9; y++)
          {
              for (int x = 0; x &lt; 9; x++)
              {
                  newStreamOut &lt;&lt; m_grid[y][x] &lt;&lt; " ";
  
              }
              newStreamOut &lt;&lt; endl;
          }
  
  
      } 
  
  
      ostream&amp; operator&lt;&lt;(ostream&amp; out, Grid&amp; grid)
      {
          grid.SaveGrid(out);
          return out;
      }
  
      istream&amp; operator&gt;&gt;(istream&amp; in, Grid&amp; grid)
      {
          grid.LoadGrid(in);
          return in;
      }
  </code></pre>
  
  <p><strong>Grid.h</strong></p>
  
  <pre><code>#pragma once
  #include&lt;ostream&gt;
  using namespace std;
  class Grid
  {
  public:
      Grid() {};
      ~Grid(){};
  
      friend ostream&amp; operator&lt;&lt;(ostream&amp; out, Grid&amp; grid);
      friend istream&amp; operator&gt;&gt;(istream&amp; in, Grid&amp; grid);
  
      void LoadGrid(const char filename[]);
      void SaveGrid(const char filename[]); 
  
  
  private:
  
      int m_grid[9][9];
  };
  </code></pre>
  
  <p><strong>main.cpp</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "Grid.h"
  using namespace std;
  
  int main(int args, char** argv)
  {
      Grid grid;
      grid.LoadGrid("Grid1.txt");
      grid.SaveGrid("OutGrid.txt");
      system("pause");
  }
  </code></pre>