title: inserting text before each line using std::ostream
body: <p>I would like to know if it is possible to inherit from std::ostream, and to override flush() in such a way that some information (say, the line number) is added to the beginning of each line. I would then like to attach it to a std::ofstream (or cout) through rdbuf() so that I get something like this:</p>
  
  <pre><code>ofstream fout("file.txt");
  myostream os;
  os.rdbuf(fout.rdbuf());
  
  os &lt;&lt; "this is the first line.\n";
  os &lt;&lt; "this is the second line.\n";
  </code></pre>
  
  <p>would put this into file.txt</p>
  
  <pre><code>1 this is the first line.
  2 this is the second line.
  </code></pre>