1: //vector_c.cpp
3: #include <iostream>
4: #include <vector>
5: #include <deque>
6: #include <list>
7: #include <algorithm>
8: #include <iterator>
9: using namespace std;
11: int main()
12: {
13: cout << "\nThis program illustrates initialization of a vector "
14: "with components\nfrom non-vector containers. In this case, "
15: "we use a deque and a list.";
16: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
18: int a[] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};
20: deque<int> intDeque(a, a+5);
21: cout << "\nHere are the contents of the deque:\n";
22: copy(intDeque.begin(), intDeque.end(),
23: ostream_iterator<int>(cout, " "));
24: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
26: list<int> intList(a+5, a+10);
27: cout << "\nHere are the contents of the list:\n";
28: copy(intList.begin(), intList.end(),
29: ostream_iterator<int>(cout, " "));
30: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
32: vector<int> vFromDeque(intDeque.begin(), intDeque.end());
33: cout << "\nHere are the contents of the vector "
34: "initialized from the deque:\n";
35: copy(vFromDeque.begin(), vFromDeque.end(),
36: ostream_iterator<int>(cout, " "));
37: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
39: vector<int> vFromList(intList.begin(), intList.end());
40: cout << "\nHere are the contents of the vector "
41: "initialized from the list:\n";
42: copy(vFromList.begin(), vFromList.end(),
43: ostream_iterator<int>(cout, " "));
44: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n');
45: }