Fast controlled copy from istream to ostream

I have to copy several bytes from a istream to a ostream, there are 2 ways that I know to perform this copy.

myostream << myistream.rdbuf();

and

copy( istreambuf_iterator<char>(myistream),
      istreambuf_iterator<char>(),
      ostreambuf_iterator<char>(myostream)
);

I've found that rdbuf version is at least twice as fast as the copy.
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 rdbuf version if posible.

How to limit those copies to a given number of bytes?

15
задан Cœur 7 August 2018 в 05:30
поделиться