Possible Duplicate:
How to read arbitrary number of values using std::copy?
Hello.
I'm reading nums from file. I do it with std::copy
copy(istream_iterator<int>(input_file),
istream_iterator<int>(),
back_inserter(first));
But this function copy only whole file, although I want to copy开发者_运维技巧 only N symbols. Thanks.
SGI's STL reference is quite good. The second argument needs to be the number of items you want to read.
Update
(After changing your initial post, which used copy_n
)
You can use a simple loop to do what you want, as in
template <typename Input, typename Output>
Output copy_n (Input i, size_t N, Output o)
{
for (; N > 0; --N)
{
*o = *i;
++i;
++o;
}
return o;
}
精彩评论