title: Loading txt file into an array of classes C++
body: <p>I'm trying to load some values from a text file and output it. When it outputs, I only receive the last row on the txt file....Why is it reading in only the last line on the txt file? I made an array of classes and load into each one of them the data from the file and i want to output it. any advice helps thanks
  main file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "membertype.h"
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  #include &lt;fstream&gt;
  #include &lt;cstdlib&gt;
  
  memberType members[500];
  int getMembersData();
  void printMembersData();
  
  int main(int argc, char** argv)
  {
      memberType();
      getMembersData();
      printMembersData();
  
      return 0;
  }
  
  int getMembersData()
  {
      cout &lt;&lt; fixed &lt;&lt; setprecision(2);
      double spent;
      int bbought;
      string fname, lname,id;
      ifstream infile;
      infile.open("project8.txt");
      if(!infile)
      {
          cout &lt;&lt; "unable to open input file. "&lt;&lt; endl;
          return 1;
      }
  
      infile&gt;&gt;id&gt;&gt;fname&gt;&gt;lname&gt;&gt;bbought&gt;&gt;spent;
      while ( !infile.eof())
      {
          for(int j=0;j&lt;5;j++)
          {
              members[j].setMemberInfo(id,fname,lname,bbought,spent);
          }
  
          infile&gt;&gt;id&gt;&gt;fname&gt;&gt;lname&gt;&gt;bbought&gt;&gt;spent;
      }
      infile.close();
  
      return EXIT_SUCCESS;
  }
  
  void printMembersData()
  {
      for(int i=0;i&lt;5;i++)
          members[i].printInfo();
  }
  </code></pre>
  
  <p>implementation file:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;string&gt;
  #include"membertype.h"
  using namespace std;
  
  memberType::memberType()
  {
      string memberID ="non";
      string firstName="emp";
      string lastName="bloop";
      int booksPurchased=0;
      double amountSpent=0;
  }
  
  void memberType::setMemberInfo(string ID, string fName, string lName, int bPurchased, double amount)
  {
      memberID = ID;
      firstName = fName;
      lastName = lName;
      booksPurchased = bPurchased;
      amountSpent = amount;
  }
  
  void memberType::printInfo()
  {
      cout&lt;&lt;memberID&lt;&lt;firstName&lt;&lt;lastName&lt;&lt;booksPurchased&lt;&lt;amountSpent&lt;&lt;endl;
  }
  </code></pre>