title: how to retrieve data from a txt file in c++
body: <p>the problem that im having is this that i am able to create a text file, write to a text once. i want to be able to add more lines to it when necessary without creating a new file. my next problem is that i cant seem to get the output that im looking for. eg. text file contain </p>
  
  <blockquote>
    <p>start1<br>
    fname|lname|ssn<br>
    end1</p>
  </blockquote>
  
  <p>my aim is to only get data within start1 and end1 and return fname lname and ssn without the delimiter |. here is my code</p>
  
  <pre><code>int main()
  {
      fstream filestr;
      string line;
  
      filestr.open ("file.txt", fstream::in | fstream::out | fstream::app);
      if(!filestr.is_open())
      {
          cout &lt;&lt; "Input file connection failed.\n";
          exit(1); 
      }
      else{
          filestr&lt;&lt;"Start2\n";
          filestr&lt;&lt; "middle|middle"&lt;&lt;endl;
          filestr&lt;&lt;"end2"&lt;&lt;endl;
          if(filestr.good()){
              while(getline(filestr, line) &amp;&amp; line !="end1"){
                  if(line !="Start1"){
                      //below this point the output goes screwy
                      while(getline(filestr, line,'|')){
                          cout&lt;&lt;"\n"&lt;&lt;line;
                      }
                  }
              }
          }
          filestr.close();
      }
  </code></pre>