title: Adding element to vector
body: <p>I was wondering why im losing the information.</p>
  
  <p>I have three functions thus far.</p>
  
  <p>An option processing function, and two vector functions one for reading a text file and the other for adding a user specifcation to the same vector.</p>
  
  <p>Whats happening is that i read the file and save its contents into a vector and then choose the next option to add a specification. To do that i use push_back. I output ( or debug ) to see if i was succesful. yes. So i choose the option that reads the file again, and im back to where i started. The users spec was lost. And i think its because im allocating it every time i enter that option. </p>
  
  <p>Im a begginner so my code is not up to most programming standards.</p>
  
  <p>Heres my first function which isolates feilds delimted by commas, saved into structure member varaibles, then saved into a vector as elements for each line in the file.</p>
  
  <pre><code>vector&lt;sStruct&gt; * loadFile(char *myTextFile)
  {
      myStruct 
          sStruct; 
      vector&lt;myStruct&gt; 
          vectorAddress,
          *vectorData = new vector&lt;myStruct&gt;
      string 
          feild1, feild2, feild3, feild4;
  
      ifstream 
          *inFile = new ifstream;
  
      inFile-&gt;open( myTextFile, ios::in );
  
  
      if ( !inFile-&gt;good() )
      {
           cout &lt;&lt; "? File Doesnt Exist! " &lt;&lt; endl;
      }
  
      while ( !inFile-&gt;eof() )
      {
  
           getline( *inFile, feild1, ',' );
           sStruct.m_1 = field1;
           getline( *inFile, feild2, ',' );
           sStruct.m_2 = field2;
           getline( *inFile, field3, ',' );
           sStruct.m_3; = feild3
           getline( *inFile, feild4 );
           sStruct.m_4 = feield4;
  
      vectorData-&gt;push_back( sStruct );
  
      }
  
      inFile-&gt;clear();
      inFile-&gt;close();
      cout &lt;&lt; vectorData-&gt;size();
      delete inFile;   // allocated obj delete to fast why bother?
      return vectorData;
  }
  </code></pre>
  
  <p>This function is successful in adding another element into the vector.</p>
  
  <pre><code>vector&lt;sStruct&gt; *  addElement(vector&lt;sStruct&gt; *vAddElement)
  {    
      sStruct addElement;  // referring to the same struct.
      cout &lt;&lt; "Enter a String: ";
      cin  &gt;&gt; addElement.feild1
  
      vAddElement-&gt;push_back( addElement );
      cout &lt;&lt; vAddElement-&gt;size() &lt;&lt; endl;
      return vAddElement;
  }
  </code></pre>
  
  <p>When im in the first function, i debug my vector object, and the data from the file is saved. ok. So i go to the next function and add a string to the struct member that has the first feild. Hopefully not overwritting anything. I debug to make sure and nope, its all good, push_back works nice. But, when i go to my first function. Everythingn is back as it was when is started. </p>
  
  <p>I know its because im reading the file there, and allocating each time i enter that function. Is there a way to prevent this?</p>