title: Send formatted char array to ostream without extra memory copying
body: <p>I need to send a char array to ostream. Say I have the following print function:</p>
  
  <p>Version 1:</p>
  
  <pre><code>void print(ostream &amp;out, const char *str, unsigned len)
  {
      out &lt;&lt; string(str,len);
  }
  </code></pre>
  
  <p>Version 2:</p>
  
  <pre><code>void print(ostream &amp;out, const char *str, unsigned len)
  {
      out.write(str,len);
  }
  </code></pre>
  
  <p>Both versions above work to a certain extent.
  Version 1 looks less efficient because it will create an extra string object (causing memory allocation and data copying). </p>
  
  <p>However Version 2 eliminates formatting possibilities. In the following example Version 1 works great (meaning that io manipulator successfully sets width to 10 and applies it to the next output field) :</p>
  
  <pre><code>out &lt;&lt; setw(10);
  print(out,s,slen);
  </code></pre>
  
  <p>Is there a way to keep functionality as in V1, but without paying extra for allocation/memcopy?</p>