title: Fast controlled copy from istream to ostream
body: <p>I have to copy several bytes from a <code>istream</code> to a <code>ostream</code>, there are 2 ways that I know to perform this copy.  </p>
  
  <pre><code>myostream &lt;&lt; myistream.rdbuf();
  </code></pre>
  
  <p>and</p>
  
  <pre><code>copy( istreambuf_iterator&lt;char&gt;(myistream),
        istreambuf_iterator&lt;char&gt;(),
        ostreambuf_iterator&lt;char&gt;(myostream)
  );
  </code></pre>
  
  <p>I've found that <code>rdbuf</code> version is at least twice as fast as the <code>copy</code>.<br>
  I haven't found yet the way of copying just, say 100 bytes, but as the size to be copied will probably be quite big I would like to be able to use the <code>rdbuf</code> version if posible.</p>
  
  <p>How to limit those copies to a given number of bytes?</p>