|
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
main(){
int a[5] = {1,2,3,4,5};
CMyostream_iterator<int> output(cout,"*");
vector<int> v(a,a+5);
copy(v.begin(),v.end(),output);
}
程序的输出结果是:
1*2*3*4*5*
注意,编写CMyostream_iterator时不能使用 ostream_iterator
参考 copy 的help
copy
template<class InIt, class OutIt> OutIt copy(InIt first, InIt last, OutIt x);
The template function evaluates *(x + N) = *(first + N)) once for each N in the range [0, last - first), for strictly increasing values of N beginning with the lowest value. It then returns x + N. If x and first designate regions of storage, x must not be in the range [first, last]
请问,哪位前辈能给个参考。不胜感激 |
|