mycopy(我理解的copy的实现)

mac2022-06-30  45

#include<iostream> #include<iterator> #include<algorithm> #include<iterator> #include<vector> using namespace std; template<class T,class InputIterator, class OutputIterator> OutputIterator mycopy(InputIterator first, InputIterator last, OutputIterator result) { vector<T>s; vector<T>::iterator it1; for (; first != last; first++) s.push_back(*first); for (it1 = s.begin(); it1 != s.end(); it1++) { *result = *it1; result++; } return result; } int main() { int a[] = { 1,2,3,4,5 }; mycopy<int>(a, a + 5, ostream_iterator<int>(cout, " ")); system("pause"); return 0; }
最新回复(0)