title: Reading file into array of struct c++
body: <p>I am trying to read a .txt file into an array of struct in this program and display the content.<br>
  The  file looks like this:   </p>
  
  <pre><code>Smith   Jack    60    45    98  
  Harry   Hisk    45    40    78  
  Kay     Jacob   35.5  23    45  
  Dos      hed    23    20    35  
  Noa      Tom    55    12    32  
  Joe      Peni   57    49    78  
  Vin      San    25.6  23    65.5  
  Jes      Dan    24.3  12    78  
  Zi       Lee    56    49    99  
  Angi     Dev    57    48    97  
  Donald   David  60    50    96  
  Davis    Lal    47    47    80  
  Alvis   Sen     56    46    85  
  Jack    Jill    45    45    75  
  Messy   Lionel  60    49    100  
  </code></pre>
  
  <p>The code I'm running:  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  using namespace std;
  int main(){
      const int SIZE=50;
      int i;
      struct Records {
          string firstname;
          string secondname;
          float test1mark;
          float midtestmark;
          float annualmark;
      }record[SIZE];
  
      ifstream in("Data.txt");
  
      if (!in){
      cerr &lt;&lt; "File can't be opened! " &lt;&lt; endl;
      system("PAUSE");
      exit(1);
      }
      for (int i=0; i &lt; SIZE; i++){
      in &gt;&gt; record[i].firstname &gt;&gt; record[i].secondname 
      &gt;&gt;record[i].test1mark &gt;&gt; record[i].midtestmark &gt;&gt; record[i].annualmark ;
      }
      for (int i=0;i&lt; SIZE;i++) {
          cout &lt;&lt; record[i].firstname&lt;&lt;"  ";
          cout &lt;&lt; record[i].secondname&lt;&lt;" ";
          cout &lt;&lt; record[i].test1mark&lt;&lt;"  ";
          cout &lt;&lt; record[i].midtestmark &lt;&lt; "  ";
          cout &lt;&lt; record[i].annualmark &lt;&lt; "   ";
      }   
  return 0;
  } 
  </code></pre>
  
  <p>The output I'm getting:  </p>
  
  <pre><code>Smith   Jack    60      45      98  
  Harry   Hisk    45      40      78  
  Kay     Jacob   35.5    23      45  
  Dos     hed     23      20      35    
  Noa     Tom     55      12      32  
  Joe     Peni    57      49      78  
  Vin     San     25.6    23      65.5  
  Jes     Dan     24.3    12      78  
  Zi      Lee     56      49      99  
  Angi    Dev     57      48      97  
  Donald  David   60      50      96  
  Davis   Lal     47      47      80  
  Alvis   Sen     56      46      85  
  Jack    Jill    45      45      75  
  Messy   Lionel  60      49      100  
                  nan     0       8.94237e-039  
                  4.36192e-039    0       -2.3511e-038  
                  0       0       -2.3511e-038  
                  0       0       0  
                  1.32253e-038    0       1.32251e-038  
                  4.2039e-045     0       -2.11122e+037  
                  1.32251e-038    0       3.21276e-039  
                  1.4013e-045     0       -2.3511e-038  
                  1.4013e-045     0       3.76158e-037  
                  0       0       3.76158e-037  
                  0       0       1.12104e-044  
                  4.36195e-039    0       4.36194e-039  
                  3.57331e-043    0       6.0615e-039  
                  0       0       3.21276e-039  
                  4.2039e-045     0       6.41272e-039  
                  1.12104e-044    0       6.63812e-039  
                  4.36205e-039    0       -2.75237e+038  
                  0       0       6.59812e-039  
                  6.63426e-039    0       1.4013e-045  
                  0       0       6.47961e-039  
                  3.21319e-039    0       3.21319e-039  
                  6.59812e-039    0       3.21299e-039  
                  8.40779e-045    2.24208e-044    6.01433e-039  
                  6.6045e-039     0       2.54408e-029  
                  0       0       6.6045e-039  
                  0       0       6.43946e-039  
                  5.88656e-039    0       -4.12495e+011  
                  0       0       0
                  5.88656e-039    0       2.54408e-029  
                  nan     nan     6.43029e-039  
                  0       0       0
                  5.93823e-039    0       -4.12495e+011  
                  0       0       0
                  5.93823e-039    0       5.74532e-044  
                  nan     nan     5.93837e-039  
  </code></pre>
  
  <hr>
  
  <p>Process exited after 0.05447 seconds with return value 0<br>
  Press any key to continue . . .  </p>
  
  <p>Can someone tell me what's wrong with it? I've tried using pointers but it just got worse. -Beginner</p>