Or login with:
#include <algorithm> template < class InputIterator, class OutputIterator > OutputIterator copy( InputIterator first, InputIterator last, OutputIterator result );Parameters:
| Parameter | Description |
|---|---|
| first | An input iterator addressing the position of the first element in the source range |
| last | An input iterator addressing the position that is one past the final element in the source range |
| result | An output iterator addressing the position of the first element in the destination range |
#include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; int main() { int a[] = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100}; vector<int> v(a, a+10); cout <<"\nHere are the contents of v, displayed in the ""usual" way:\n"; for (vector<int>::size_type i=0; i<v.size(); i++) cout <<v.at(i)<<" "; cout <<"\nAnd here they are again, displayed this time using " "\nthe copy algorithm and an output stream iterator:\n"; copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); return 0; }
You must login to leave a messge