title: A custom ostream
body: <p>I need some guidance or pointers understanding how to implement a custom ostream. My requirements are:</p>
  
  <ol>
  <li>A class with a '&lt;&lt;' operator for several data types.</li>
  <li>The intention is to send output to database. Each "line" should go to a separate record.</li>
  <li>Each record most important field would be the text (or blob), but some other fields such as time, etc. can be mostly deduced automatically</li>
  <li>buffering is important, as I don't want to go to database for every record.</li>
  </ol>
  
  <p>First, does it worth deriving from ostream? What do I get by deriving from ostream? What if my class simply implements few <code>operator&lt;&lt;</code> methods (including some custom data types). Which functionality do I get from ostream?</p>
  
  <p>Assuming what I want is a class derived from ostream, I need some guidance understanding the relationship between the ostream and the streambuf classes. Which one do I need to implement? Looking at some samples, it appears that I don't need to derive from ostream at all, and just give the ostream constructor a custom streambuf. Is that true? is that the canonical approach?</p>
  
  <p>Which virtual functions at the custom streambuf do i need to implement? I've seen some samples (including this site: <a href="https://stackoverflow.com/q/760301/341971">here</a> and <a href="https://stackoverflow.com/q/4366904/341971">here</a>, and few more), some override the <code>sync</code> method, and other override the <code>overflow</code> method. Which one should I override? Also, looking at the stringbuf and filebuf sources (Visual Studio or GCC) both those buffer classes implement many methods of the streambuf.</p>
  
  <p>If a custom class derived from streambuf is required, would there be any benefit deriving from stringbuf (or any other class) instead of directly from streambuf?</p>
  
  <p>As for "lines". I would like at least when my users of the class using the 'endl' manipulator to be a new line (i.e. record in database). Maybe - depends on effort - every '\n' character should be considered as a new record as well. Who do my custom ostream and/or streambuf get notified for each?</p>