title: Empty line at the end of the output
body: <p>So I have a &quot;db.csv&quot; data file. Code reads each value from the file separated by a comma (value1, ...). Unnecessary spacings from the lines are deleted, then the finished line is printed out as desired (one space between values). The problem is that I have to pass the tests on a site called repl.it. And I fail every test, because there is an extra blank line at the end of the output. Any suggestions? I know, that it's probably because of the endl at the cout, but how else do I do it?</p>
  <p>Minimal reproducible code:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;algorithm&gt;
  #include &lt;sstream&gt;
  
  using namespace std;
  
  int main() {
      fstream file(&quot;db.csv&quot;, ios::in);
      string value1, value2, value3, value4, value5, line;
  
      cout &lt;&lt; &quot;result:&quot; &lt;&lt; endl;
  
      while (getline(file, line)) {
          if (line.length() &gt; 1) {
              istringstream str1(line);
  
              while (getline(str1, value1, ','),
                     getline(str1, value2, ','),
                     getline(str1, value3, ','),
                     getline(str1, value4, ','),
                     getline(str1, value5, '\n')) {
                  value1.erase(remove(value1.begin(), value1.end(), ' '), value1.end());
                  value2.erase(remove(value2.begin(), value2.end(), ' '), value2.end());
                  value3.erase(remove(value3.begin(), value3.end(), ' '), value3.end());
                  value4.erase(remove(value4.begin(), value4.end(), ' '), value4.end());
                  value5.erase(remove(value5.begin(), value5.end(), ' '), value5.end());
  
                  cout &lt;&lt; value1 &lt;&lt; &quot; &quot; &lt;&lt; value2 &lt;&lt; &quot; &quot; 
                       &lt;&lt; value3 &lt;&lt; &quot; &quot; &lt;&lt; value4 &lt;&lt; &quot; &quot; 
                       &lt;&lt; value5 
                       &lt;&lt; endl;
              }
          }
      } 
  }
  </code></pre>
  <p>db.csv file data:</p>
  <pre><code>Riga,Kraslava,Pr,15:00,11.00
  
  Riga ,Kraslava,Pr ,18:00,11.00
     Kraslava,Riga,Pr,08:00,11.00
  Kraslava,Daugavpils,Ot ,10:00, 3.00
  Ventsplis,8.00,Liepaja,Sv,20:00
  Dagda,Sv
  
  Rezekne,Riga,Tr,13:00,10.50
  Dagda,Kraslava,  Ce,18:00,  2.50
  Dagda,Kraslava,Ce,18:00,2.50,Sv
    Riga,Ventspils,  Pt,09:00  ,  6.70
  
  Liepaja,Ventspils,Pt,17:00,5.50
  </code></pre>
  <p>Output:</p>
  <pre><code>Riga Kraslava Pr 15:00 11.00
  Riga Kraslava Pr 18:00 11.00
  Kraslava Riga Pr 08:00 11.00
  Kraslava Daugavpils Ot 10:00 3.00
  Ventsplis 8.00 Liepaja Sv 20:00
  Rezekne Riga Tr 13:00 10.50
  Dagda Kraslava Ce 18:00 2.50
  Dagda Kraslava Ce 18:00 2.50,Sv
  Riga Ventspils Pt 09:00 6.70
  Liepaja Ventspils Pt 17:00 5.50
  *blank line*
  </code></pre>
  <p>Desired output:</p>
  <pre><code>Riga Kraslava Pr 15:00 11.00
  Riga Kraslava Pr 18:00 11.00
  Kraslava Riga Pr 08:00 11.00
  Kraslava Daugavpils Ot 10:00 3.00
  Ventsplis 8.00 Liepaja Sv 20:00
  Rezekne Riga Tr 13:00 10.50
  Dagda Kraslava Ce 18:00 2.50
  Dagda Kraslava Ce 18:00 2.50,Sv
  Riga Ventspils Pt 09:00 6.70
  Liepaja Ventspils Pt 17:00 5.50
  </code></pre>