title: C++ How do I delete a new line from the end of a text file?
body: <p>I'm deleting a line from a text file by copying each line, except for the one line specified by the user which is to be deleted, to a new text file (temp.txt) and then deleting the original text file (staffMembers.txt) and renaming temp.txt to staffMembers.txt.</p>
  
  <p>The content of staffMembers.txt is as follows:</p>
  
  <pre><code>1 | First Person | Manager | 123.45
  2 | Second Person | Full Time | 123.45
  3 | Third Person | Casual | 123.45
  </code></pre>
  
  <p>When the content of staffMembers.txt is copied to temp.txt it is as follows:</p>
  
  <pre><code>1 | First Person | Manager | 123.45
  2 | Second Person | Full Time | 123.45
  3 | Third Person | Casual | 123.45
  *** new line ***
  </code></pre>
  
  <p>Could someone please explain how I can prevent that new line from being created at the end of the text file? My code is as follows:</p>
  
  <pre><code>void deleteStaffMember()
  {
      outStream.open("temp.txt", ios::app);
  
      if(outStream.fail())
      {
          cout &lt;&lt; "Unable to open temp.txt.\n";
          exit(1);
      }
  
      inStream.open("staffMembers.txt");
  
      if(inStream.fail())
      {
          cout &lt;&lt; "Unable to open staffMembers.txt.\n";
          exit(1);
      }
      else
      {
          cout &lt;&lt; endl &lt;&lt; "Please enter a staff members ID to delete: ";
          cin &gt;&gt; deleteLine;
  
          while(getline(inStream, line))
          {
              string firstCharacter;
  
              firstCharacter += line[0];
  
              if (firstCharacter != deleteLine)
              {
                  outStream &lt;&lt; line &lt;&lt; endl;
              }
              else
              {
                  inStream.close();
  
                  outStream.close();
  
                  cout &lt;&lt; "Error. Unable to find staff member.\n" &lt;&lt; endl;
  
                  break;
              }
          }
      }
  
      inStream.close();
  
      outStream.close();
  
      remove("staffMembers.txt");
  
      rename("temp.txt", "staffMembers.txt");
  
      cout &lt;&lt; "The staff member has been deleted successfully.\n" &lt;&lt; endl;
  
      system("pause");
  
      system("cls");
  }
  </code></pre>
  
  <p>I cannot remove <strong><em>endl</em></strong> from <strong><em>outStream &lt;&lt; line &lt;&lt; endl;</em></strong> because then temp.txt is formatted like the following:</p>
  
  <pre><code>1 | First Person | Manager | 123.452 | Second Person | Full Time | 123.453 | Third Person | Casual | 123.45
  </code></pre>