Source of deque13.cpp


  1: //deque13.cpp

  3: #include <iostream>
  4: #include <string>
  5: #include <deque>
  6: using namespace std;

  8: int main()
  9: {
 10:     cout << "\nThis program illustrates the resize() member "
 11:         "function for deque objects.";
 12:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 14:     deque<int> d1;
 15:     cout << "\nTo begin we have, for d1:";
 16:     cout << "\nSize = " << d1.size();
 17:     cout << "\nContents: ";
 18:     for(deque<int>::size_type i=0; i<d1.size(); i++)
 19:         cout << d1.at(i) << " ";
 20:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 22:     d1.resize(4);
 23:     cout << "\nAfter d1.resize(4) we have, for d1:";
 24:     cout << "\nSize = " << d1.size();
 25:     cout << "\nContents: ";
 26:     for(deque<int>::size_type i=0; i<d1.size(); i++)
 27:         cout << d1.at(i) << " ";
 28:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 30:     deque<int> d2(10, 3);
 31:     cout << "\nTo begin we have, for d2:";
 32:     cout << "\nSize = " << d2.size();
 33:     cout << "\nContents: ";
 34:     for(deque<int>::size_type i=0; i<d2.size(); i++)
 35:         cout << d2.at(i) << " ";
 36:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 38:     d2.resize(8);
 39:     cout << "\nAfter d2.resize(8) we have, for d2:";
 40:     cout << "\nSize = " << d2.size();
 41:     cout << "\nContents: ";
 42:     for(deque<int>::size_type i=0; i<d2.size(); i++)
 43:         cout << d2.at(i) << " ";
 44:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 46:     d2.resize(12);
 47:     cout << "\nAfter d2.resize(12) we have, for d2:";
 48:     cout << "\nSize = " << d2.size();
 49:     cout << "\nContents: ";
 50:     for(deque<int>::size_type i=0; i<d2.size(); i++)
 51:         cout << d2.at(i) << " ";
 52:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 54:     d2.resize(6, -1);
 55:     cout << "\nAfter d2.resize(6, -1) we have, for d2:";
 56:     cout << "\nSize = " << d2.size();
 57:     cout << "\nContents: ";
 58:     for(deque<int>::size_type i=0; i<d2.size(); i++)
 59:         cout << d2.at(i) << " ";
 60:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 62:     d2.resize(10, -1);
 63:     cout << "\nAfter d2.resize(10, -1) we have, for d2:";
 64:     cout << "\nSize = " << d2.size();
 65:     cout << "\nContents: ";
 66:     for(deque<int>::size_type i=0; i<d2.size(); i++)
 67:         cout << d2.at(i) << " ";
 68:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');

 70:     d2.resize(20, -2);
 71:     cout << "\nAfter d2.resize(20, -2) we have, for d2:";
 72:     cout << "\nSize = " << d2.size();
 73:     cout << "\nContents: ";
 74:     for(deque<int>::size_type i=0; i<d2.size(); i++)
 75:         cout << d2.at(i) << " ";
 76:     cout << "\nPress Enter to continue ... ";  cin.ignore(80, '\n');
 77: }