title: PushBack Objects on a vector c++
body: <p>I have this:</p>
  
  <pre><code>void StudentRegister::ReadDataFromFile(){
  try{
      streampos begin,end;        
      char delimeter[3] = {',', '\n', '\0'};
      int numChars = 0, tmpNumChars = 0;
      int pos1 = 0, pos2 = 0, pos3 = 0, startIndex = 0;
      ifstream file1("Students.txt", ios::in);
      if (!file1) throw MyExceptions();
      begin = file1.tellg();
      file1.seekg (0, ios::end);
      end = file1.tellg();
      int size =  end - begin;
      file1.seekg(0, ios::beg);      
      char charField[size];
      Student student;
      int k = 0;
      while(file1.getline(charField, size, '\n'))
      { 
          char *tmpCharField1 = charField;                        
          numChars = file1.gcount();
          CustomString tmpStudent(tmpCharField1, numChars);
          pos1 = tmpStudent.findCharacter(&amp;delimeter[0], startIndex);
          CustomString tmpStudentCode = tmpStudent.subString(startIndex, pos1);
          pos2 = tmpStudent.findCharacter(&amp;delimeter[0], (pos1 + 1));
          CustomString tmpFirstName = tmpStudent.subString((pos1 + 1), pos2);
          pos3 = tmpStudent.findCharacter(&amp;delimeter[2], (pos2 + 1));
          CustomString tmpSecondName = tmpStudent.subString((pos2 + 1), pos3);
          student = Student(tmpStudentCode, tmpFirstName, tmpSecondName);
          this-&gt;StudentVector.push_back(&amp;student);
          numChars = 0;
          k++;
          if (k == 4){
              cout &lt;&lt; this-&gt;StudentVector.size()&lt;&lt; endl;
              for (int i = 0 ; i &lt; this-&gt;StudentVector.size(); i ++){
                vector&lt;CustomString&gt; tt = this-&gt;StudentVector.at(i)-&gt;PrintData();
                for (int j =0; j &lt; tt.size(); j++){
                   tt.at(j).PrintData();
                }
  
             }}            
      }        
      file1.close();
     }}}
  </code></pre>
  
  <p>Student PrintData is like that:</p>
  
  <pre><code>//Print Data Method
  vector&lt;CustomString&gt; Student::PrintData(){
  char tmp1[] = {'S','t','u','d','e','n','t','C','o','d','e','='};
  char tmp2[] = {'F','i','r','s','t','N','a','m','e','='};
  char tmp3[] = {'S','e','c','o','n','d','N','a','m','e','='};
  vector&lt;CustomString&gt; tmpStudentVector;
  CustomString tmp1String(tmp1, 12);
  CustomString tmp2String(tmp2, 10);
  CustomString tmp3String(tmp3, 11);
  tmpStudentVector.push_back(tmp1String);
  tmpStudentVector.push_back(this-&gt;Code);
  tmpStudentVector.push_back(tmp2String);
  tmpStudentVector.push_back(this-&gt;FirstName);
  tmpStudentVector.push_back(tmp3String);
  tmpStudentVector.push_back(this-&gt;SecondName);
  for (int i = 0 ; i &lt; this-&gt;StudentCourses.size(); i ++){
      vector&lt;CustomString&gt; tmpCourseVector = ((Course)(this-&gt;StudentCourses.at(i))).PrintData();
      for (int j = 0; j &lt; tmpCourseVector.size(); j++){
          tmpStudentVector.push_back(tmpCourseVector.at(j));
      }    
  } 
  return tmpStudentVector;
  }
  </code></pre>
  
  <p>while CustomString PrintData is like that:</p>
  
  <pre><code>//Print CandidateString
  void CustomString::PrintData(){
  for (int i = 0 ; i &lt; this-&gt;NumberOfChars ; i ++){
      cout &lt;&lt; this-&gt;CandidateString[i] &lt;&lt; " " ;
  }
  cout &lt;&lt; endl;
  }
  </code></pre>
  
  <p>This is the StudentRegister class where the ReadDataFromFile is:</p>
  
  <pre><code>class StudentRegister{
  public:
    StudentRegister();  //Constructor
    StudentRegister(const StudentRegister &amp;);  //Copy Constructor      
    vector&lt;Student *&gt; getStudentVector(); //StudentVector Getter     
    void setStudentVector(vector&lt;Student *&gt; &amp;); //StudentVector Setter    
    void ReadDataFromFile(); //Read Data From Excel
    bool FindStudentOnVector(CustomString &amp;); //Find if student exists
    Student GetStudentFromVector(CustomString &amp;); //Get Student from StudentVector
    bool FindCourseOnVector(CustomString &amp;); //Find if Course exists  
    bool operator() (const Course &amp;, const Course &amp;); //Compare function, Needed to construct the Map    
    void PrintData(); //PrintData Method
    ~StudentRegister(); //Destructor
  private:     
    vector&lt;Student *&gt; &amp;StudentVector; //StudentVector Property     
    CustomString &amp;ErrorString;     
  };
  </code></pre>
  
  <p>Now do not ask why I an using all this code to return and print just all the nessecary properties, it is an assignment i do no have to use any string class or any relative string.h method. I have to use only char and pointers. The strange is that this->StudentVector on ReadDataFromFile() when I try to print the Student objects I get only the final object where is Student number 4, The size of StudentVector is 4, the code above in ReadDataFromFile() has a breakpoint for debugging there where k == 4 is checked.It seems the vector holds only the final object.Any suggestion?</p>