注册 登录
编程论坛 C++教室

求助C++达人

welcomedz 发布于 2008-06-07 08:14, 944 次点击
#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]

请问,哪位前辈能给个参考。不胜感激
1 回复
#2
stdlll2008-06-07 14:16
#include<iterator>
...
copy(v.begin(),v.end(),ostream_iterator(cout, "*");
1