If I know for certain that my input stream contains 10 values, I can read them with
std::copy_n(std::istream_iterator<T>(input), 10, output);
If I don't know how much values I have, I can read all of them with
std::copy(std::istream_iterator<T>(input), std::istream_iterator<T>(), output);
My problem is how to read up to 10 values. I'm trying to be robust against I/O errors here,
but it appears that copy_n
will try to read past the end of the input (it doesn't know that it should stop), and copy
won't stop at 10 values. Do I have to roll my own copy_at_most
?
(Well, there's apparently some confusion about copy_n anyway: std::istream_iterator<> with copy_n() and friends )