c++ using function of type void or std::ostream & to do prints?
<p>I am wondering what the reasons and advantages of defining a function with an <code>std::ostream &amp;</code> return type are as opposed to just a void function for printing values. For instance if I wanted to print a string literal I could do it in the following two ways:</p>

<pre><code>std::ostream&amp; print1(std::ostream &amp;os){
     os &lt;&lt; "print this message";
     return os;
}
print1(std::cout);
</code></pre>

<p>or</p>

<pre><code>void print2(){
     std::cout &lt;&lt; "print this message";
}
print2();
</code></pre>

<p>Now what would be the advantage of using a function like <code>print1</code> as opposed to <code>print2</code>? Is one more efficient than the other, and are there other important differences?   </p>