title: (C++) Overloading operator << , overwrite the output if I do not use endl
body: <p>I am doing a C++ project for the university. I have to make a chronology of historical events. I have a class to save the events, called "FechaHistorica", with a <code>set&lt;string&gt;</code> and <code>int</code> as private members. The set contains strings, each string is one historical event. The int is the year when all that events happened.
  The other class is called "Cronologia", with a <code>map&lt;int,FechaHistorica&gt;</code> to store every "FechaHistorica".</p>
  
  <p>The problem is with the operator &lt;&lt; of FechaHistorica I guess. The executbale recives two .txt files with movies, and the outpout should be the union of both documents. Here is the code for the operator &lt;&lt; os FechaHistorica:</p>
  
  <pre><code>const char SEP = '#';
  ostream&amp; operator&lt;&lt; (ostream&amp; os, const FechaHistorica&amp; e) {
      os &lt;&lt; e.getYear();
  
      for(const_iterator p = e.eventos.begin(); p != e.eventos.end(); ++p)
          os &lt;&lt; SEP &lt;&lt; *p;
  
      return os;
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>victor@victor-GL552VW:~/Documentos/Universidad/1º Cuatrimestre/Estructura de dat
  os/Practicas/Practicas-ED/Práctica 4 - STL e Iteradores$ ./bin/prueba movies.txt
   films.txt
  Cronología leida del archivo: 
  0
  1900#Sherlock Holmes Baffled#The Enchanted Drawing
  1901#Scrooge, or, Marley's Ghost#Star Theatre
  1902#A Trip to the Moon
  #The Great Train Robbery Fireman
  1904#The Impossible Voyage
  1905#Adventures of Sherlock Holmes; or, Held for Ransom
  #Humorous Phases of Funny Faces#The Story of the Kelly Gang
  1907#Ben Hur#L'Enfant prodigue
  #Fantasmagorie#The Assassination of the Duke of Guise#The Taming of the Shrew#The Thieving Hand
  #The Country Doctoreat#Les Misérables#Princess Nicotine; or, The Smoke Fairy
  1910#In Old California'
  1911#Defence of Sevastopol#L'Inferno
  1912#Independenţa României#The Musketeers of Pig Alley
  1913#Barney Oldfield's Race for a Life#Fantômas#Raja Harishchandra#The Bangville Police
  1914#Judith of Bethulia#The Perils of Pauline#Tillie's Punctured Romance
  1915#A Fool There Was#Birth of a Nation#Les Vampires#The Tramp
  </code></pre>
  
  <p>As you can see, some years are not printed correct, the output should be:</p>
  
  <pre><code>1900#Sherlock Holmes Baffled#The Enchanted Drawing
  1901#Scrooge, or, Marley's Ghost#Star Theatre
  1902#A Trip to the Moon
  1903#The Great Train Robbery#Life of an American Fireman
  1904#The Impossible Voyage
  1905#Adventures of Sherlock Holmes; or, Held for Ransom
  1906#The Story of the Kelly Gang#Humorous Phases of Funny Faces#Dream of a Rarebit Fiend
  1907#Ben Hur#L'Enfant prodigue
  1908#Fantasmagorie#The Taming of the Shrew#The Thieving Hand#The Assassination of the Duke of Guise#A Visit to the Seaside
  1909#The Country Doctor#A Corner in Wheat#Les Misérables#Princess Nicotine; or, The Smoke Fairy
  1910#In Old California'
  1911#L'Inferno#Defence of Sevastopol
  1912#Independenţa României#The Musketeers of Pig Alley
  1913#The Bangville Police#Barney Oldfield's Race for a Life#Fantômas#Raja Harishchandra
  1914#The Perils of Pauline#Judith of Bethulia#Tillie's Punctured Romance
  1915#Birth of a Nation#Les Vampires#The Tramp#A Fool There Was
  </code></pre>
  
  <p>Well, if I add <code>endl</code> after every event, the output is correct, I mean,  <code>os &lt;&lt; SEP &lt;&lt; *p &lt;&lt; endl;</code> instead of  <code>os &lt;&lt; SEP &lt;&lt; *p;</code>, but I don't want to have endl after each historical event in the output. What can I do?</p>
  
  <p>I hope you can help me, thanks.</p>
  
  <p>The files with data are "movies.txt" and "films.txt"
  The full code of the proyect is here: <a href="https://github.com/vicase/Practicas-ED/tree/master/Pr%C3%A1ctica%204%20-%20STL%20e%20Iteradores" rel="nofollow noreferrer">https://github.com/vicase/Practicas-ED/tree/master/Pr%C3%A1ctica%204%20-%20STL%20e%20Iteradores</a></p>