Can you use 0x? If so, then you can use copy_n:
copy_n( istreambuf_iterator<char>(myistream),
100,
ostreambuf_iterator<char>(myostream)
);
EDIT 1:
I know you're probably looking for a library solution, and you could probably have figured this out on your own. But in case you haven't thought of something like this, here's what I would do(if I didn't have copy_n):
void stream_copy_n(std::istream & in, std::size_t count, std::ostream & out)
{
const std::size_t buffer_size = 4096;
char buffer[buffer_size];
while(count > buffer_size)
{
in.read(buffer, buffer_size);
out.write(buffer, buffer_size);
count -= buffer_size;
}
in.read(buffer, count);
out.write(buffer, count);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…