title: How to print 2D Arrays in C++?
body: <p>I am trying to print a text file out on screen using arrays, but I'm not sure why it does not appear the way it is in the text file.</p>
  
  <p>The text file:</p>
  
  <pre><code>1 2 3 4
  5 6 7 8
  </code></pre>
  
  <p>Displayed on the screen as follows after applying discard function:</p>
  
  <pre><code>1
  2
  3
  4
  5
  6
  7
  8
  </code></pre>
  
  <p><strong>The code:</strong></p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  const int MAX_SIZE = 20;
  const int TOTAL_AID = 4;
  
  void discard_line(ifstream &amp;in);
  void print(int print[][4] , int size);
  
  int main()
  {
      //string evnt_id[MAX_SIZE]; //stores event id
      int athlete_id[MAX_SIZE][TOTAL_AID]; //stores columns for athelete id
      int total_records;
      char c; 
      ifstream reg;
      reg.open("C:\\result.txt");
  
      discard_line(reg);
      total_records = 0;
  
      while( !reg.eof() )
      {
          for (int i = 0; i &lt; TOTAL_AID; i++)
          {
              reg &gt;&gt; athlete_id[total_records][i] ;//read aid coloumns
          }
          total_records++;
          reg.get(c);
      }
  
      reg.close();
  
      print(athlete_id, total_records);
  
      system("pause");
      return 0;
  }
  
  void discard_line(ifstream &amp;in)
  {
      char c;
  
      do
          in.get(c);
      while (c!='\n');
  }
  
  void print(int print[][4] , int size)
  {    
      cout &lt;&lt; " \tID \t AID " &lt;&lt; endl;
      for (int i = 0; i &lt; size; i++)
      {
          for (int j = 0; j &lt; TOTAL_AID; j++)
          {
              cout &lt;&lt; print[i][j] &lt;&lt; endl;
          }           
      }
  }    
  </code></pre>