title: Printing a potentially empty istream into an ostream
body: <p>I want to put the contents of an <a href="https://en.cppreference.com/w/cpp/io/basic_istream" rel="nofollow noreferrer"><code>istream</code></a> into an <a href="https://en.cppreference.com/w/cpp/io/basic_ostream" rel="nofollow noreferrer"><code>ostream</code></a>. I tried doing that :</p>
  
  <pre><code>std::cout &lt;&lt; my_istream.rdbuf() &lt;&lt; '\n';
  </code></pre>
  
  <p>But when the <code>istream</code> happens to be empty, it triggers the <code>failbit</code> of the <code>ostream</code> (cf. <a href="https://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt" rel="nofollow noreferrer"><code>operator&lt;&lt;</code></a>, overload 9), which causes the <code>'\n'</code> and anything subsequent to not be printed.</p>
  
  <p>Why does it trigger the <code>failbit</code> (what is the reasoning for doing that ?), and is there an other way to print a stream that doesn't consider an empty one to be an error ?</p>
  
  <p><strong>EDIT:</strong> To avoid the issue I could just do :</p>
  
  <pre><code>char c;
  while(my_stream.get(c)) std::cout.put(c);
  </code></pre>
  
  <p>I would still be thankfull though if someone could point to me what was the reason that the comittee decided to trigger the <code>failbit</code> in case of an empty buffer.</p>