1: //copy_n1a.cpp
3: #include <iostream>
4: #include <algorithm>
5: #include <vector>
6: #include <deque>
7: #include <iterator>
8: using namespace std;
10: int main()
11: {
12: cout << "\nThis program illustrates the use of the STL copy_n() "
13: "algorithm from\n<algorithm> to copy the first four "
14: "integers from a vector of ten integers\nto a deque "
15: "of five integers.";
16: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
18: int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
19: vector<int> v(begin(a), end(a));
20: deque<int> d(5, -1);
21: auto endOfCopiedRange =
22: copy_n(begin(v), 4, begin(d));
23: copy(begin(d), end(d), ostream_iterator<int>(cout, " "));
24: cout << "\nThe value at the end of the copied range is "
25: << *endOfCopiedRange << ".\n";
26: cout << "Press Enter to continue ... "; cin.ignore(80, '\n');
27: }