Source of list_c.cpp


  1: //list_c.cpp

  3: #include <iostream>
  4: #include <vector>
  5: #include <deque>
  6: #include <list>
  7: using namespace std;

  9: int main()
 10: {
 11:     cout << "\nThis program illustrates initialization of a list "
 12:         "with components\nfrom non-list containers. In this case, "
 13:         "we use a vector and a deque.";
 14:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 16:     int a[] = {1, 3, 5, 7, 9, 2, 4, 6, 8, 10};

 18:     vector<int> intVector(a, a+5);
 19:     cout << "\nHere are the contents of the vector:\n";
 20:     copy(intVector.begin(), intVector.end(),
 21:         ostream_iterator<int>(cout, " "));
 22:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 24:     deque<int> intDeque(a+5, a+10);
 25:     cout << "\nHere are the contents of the deque:\n";
 26:     copy(intDeque.begin(), intDeque.end(),
 27:         ostream_iterator<int>(cout, " "));
 28:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 30:     list<int> listFromVector(intVector.begin(), intVector.end());
 31:     cout << "\nHere are the contents of the list "
 32:         "initialized from the vector:\n";
 33:     copy(listFromVector.begin(), listFromVector.end(),
 34:         ostream_iterator<int>(cout, " "));
 35:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 37:     list<int> listFromDeque(intDeque.begin(), intDeque.end());
 38:     cout << "\nHere are the contents of the list "
 39:         "initialized from the deque:\n";
 40:     copy(listFromDeque.begin(), listFromDeque.end(),
 41:         ostream_iterator<int>(cout, " "));
 42:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 43: }