title: Printing either to console or to a string/stream
body: <p>I need a C++ function that dumps some text data (multiple lines) to the console:</p>
  
  <pre><code>void DumpData() const
  {
      std::cout &lt;&lt; "My Data 1" &lt;&lt; std::endl;
      std::cout &lt;&lt; "My Data 2" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This should be the default behaviour, however, it must also be possible to pass some other stream object that would be used instead of <code>std::cout</code>, something like this:</p>
  
  <pre><code>void DumpData(std::ostream&amp; Stream = std::cout) const
  {
      Stream &lt;&lt; "My Data 1" &lt;&lt; std::endl;
      Stream &lt;&lt; "My Data 2" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Now to my questions:</p>
  
  <ol>
  <li>What is the correct type I should use for the paramter (<code>std::ostream&amp;</code> in this example)?</li>
  <li>What is the default value, can I use <code>= std::cout</code> directly?</li>
  </ol>
  
  <p>Moreover (3.), after the call to this function, if I pass my own stream object, I need to iterate over all strings in this stream line by line. What would be the best way to achieve this?</p>