1: //deque_a.cpp
3: #include <iostream>
4: #include <algorithm>
5: #include <iterator> //Redundant in VS2005 but required for g++ 3.3.3.
6: #include <deque>
7: using namespace std;
9: int main()
10: {
11: cout << "\nThis program illustrates the use of the istream_iterator "
12: "and ostream_iterator\nin conjunction with the copy algorithm "
13: "to provide \"deque I/O\".";
14: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
16: int a[] = {1, 2, 3, 4, 5};
17: deque<int> q(a, a+5);
18: cout << "\nInitial contents of q, displayed using the copy "
19: "algorithm to copy values from\nq to the standard output "
20: "with the help of an ostream_iterator:\n";
21: copy(q.begin(), q.end(), ostream_iterator<int>(cout, " "));
22: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
24: cout << "\nNow we copy some values from standard input into a deque "
25: "\nusing the copy algorithm and an istream_iterator.\nEnter five "
26: "integer values, followed by your end-of-file character:\n";
27: copy(istream_iterator<int>(cin), istream_iterator<int>(), q.begin());
28: cin.ignore(80, '\n');
29: cin.clear();
31: cout << "\nFinal contents of q: ";
32: copy(q.begin(), q.end(), ostream_iterator<int>(cout, " "));
33: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
34: }