title: Why is my array of pointers to objects not being assigned data from the txt file and instead has junk data
body: <p>The Array of pointers to objects dynamically allocates a new object each time it goes through the for loop. I am reading data into the array of pointers to objects from a .txt file. Then I use the setter functions to assign data to the array. Finally I output the data using cout and the getter functions.</p>
  
  <pre><code>int main()
  {
  
   const int SIZE = 22000;
   Baby* babyArray[SIZE];
  
   loadData(babyArray, SIZE);
  
   return 0;
  }
  
  void loadData(Baby* babyArray[], int SIZE)
  {
      fstream inFile;
      string r;
      int re;
  
      inFile.open("baby_data.txt", ios::in);
  
  for (int x = 0; x &lt; SIZE; x++) 
  {
      babyArray[x] = new Baby;
  
  
      inFile &gt;&gt; re;
      babyArray[x]-&gt;setbirthYear(re);
  
      inFile.ignore();
  
      getline(inFile, r, '\t');
      babyArray[x]-&gt;setGender(r);
  
      getline(inFile, r, '\t');
      babyArray[x]-&gt;setEthnicity(r);
  
      getline(inFile, r, '\t');
      babyArray[x]-&gt;setName(r);
  
      inFile.ignore();
  
      inFile &gt;&gt; re;
      babyArray[x]-&gt;setCount(re);
  
      inFile &gt;&gt; re;
      babyArray[x]-&gt;setRank(re);
  
      cout &lt;&lt; babyArray[x]-&gt;getbirthYear() &lt;&lt; endl;
      cout &lt;&lt; babyArray[x]-&gt;getGender() &lt;&lt; endl;
      cout &lt;&lt; babyArray[x]-&gt;getEthnicity() &lt;&lt; endl;
      cout &lt;&lt; babyArray[x]-&gt;getName() &lt;&lt; endl;
      cout &lt;&lt; babyArray[x]-&gt;getCount() &lt;&lt; endl;
      cout &lt;&lt; babyArray[x]-&gt;getRank() &lt;&lt; endl;
  
      }
  
  }
  </code></pre>
  
  <p>I need the console to print out the corresponding data from the text file.</p>
  
  <p>This is the output. There are not any build errors.
  -858993460</p>
  
  <p>-858993460
  -858993460</p>