1: //deque10.cpp 3: #include <iostream> 4: #include <deque> 5: using namespace std; 7: int main() 8: { 9: cout << "\nThis program illustrates how one deque can be " 10: "assigned to another deque\nof the same component type, " 11: "using the assignment operator (=), and also\nillustrates " 12: "the use of the assign() member function for assigning " 13: "values\nto a deque."; 14: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 16: cout << "\nFirst we demonstrate use of the assignment operator."; 17: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 19: int a1[] = {1, 2, 3, 4, 5}; 20: deque<int> d1(a1, a1+5); 21: cout << "\nFor d1 we have ..."; 22: cout << "\nSize = " << d1.size(); 23: cout << "\nContents: "; 24: for(deque<int>::size_type i=0; i<d1.size(); i++) 25: cout << d1.at(i) << " "; 26: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 28: int a2[] = {1, 2, 3, 4, 5, 6, 7}; 29: deque<int> d2(a2, a2+7); 30: cout << "\nFor d2 we have ..."; 31: cout << "\nSize = " << d2.size(); 32: cout << "\nContents: "; 33: for(deque<int>::size_type i=0; i<d2.size(); i++) 34: cout << d2.at(i) << " "; 35: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 37: int a3[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; 38: deque<int> d3(a3, a3+10); 39: cout << "\nFor d3 we have ..."; 40: cout << "\nSize = " << d3.size(); 41: cout << "\nContents: "; 42: for(deque<int>::size_type i=0; i<d3.size(); i++) 43: cout << d3.at(i) << " "; 44: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 46: d2 = d1; 47: cout << "\nNow we assign d1 to d2 (d2 = d1). " 48: "\nThen for d2 we have ..."; 49: cout << "\nSize = " << d2.size(); 50: cout << "\nContents: "; 51: for(deque<int>::size_type i=0; i<d2.size(); i++) 52: cout << d2.at(i) << " "; 53: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 55: d2 = d3; 56: cout << "\nNow we assign d3 to d2 (d2 = d3). " 57: "\nThen for d2 we have ..."; 58: cout << "\nSize = " << d2.size(); 59: cout << "\nContents: "; 60: for(deque<int>::size_type i=0; i<d2.size(); i++) 61: cout << d2.at(i) << " "; 62: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 64: cout << "\nNow we demonstrate use of the assign() member function."; 65: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 67: int a4[] = {2, 4, 6, 8}; 68: deque<int> d4(a4, a4+4); 69: cout << "\nFor d4 we have ..."; 70: cout << "\nSize = " << d4.size(); 71: cout << "\nContents: "; 72: for(deque<int>::size_type i=0; i<d4.size(); i++) 73: cout << d4.at(i) << " "; 74: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 76: d4.assign(3, 10); 77: cout << "\nNow we perform d4.assign(3, 10). " 78: "\nThen for d4 we have ..."; 79: cout << "\nSize = " << d4.size(); 80: cout << "\nContents: "; 81: for(deque<int>::size_type i=0; i<d4.size(); i++) 82: cout << d4.at(i) << " "; 83: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 85: d4.assign(6, 12); 86: cout << "\nNow we perform d4.assign(6, 12). " 87: "\nThen for d4 we have ..."; 88: cout << "\nSize = " << d4.size(); 89: cout << "\nContents: "; 90: for(deque<int>::size_type i=0; i<d4.size(); i++) 91: cout << d4.at(i) << " "; 92: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 94: int a5[] = {1, 3, 5, 7, 9}; 95: deque<int> d5(a5, a5+5); 96: cout << "\nFor d5 we have ..."; 97: cout << "\nSize = " << d5.size(); 98: cout << "\nContents: "; 99: for(deque<int>::size_type i=0; i<d5.size(); i++) 100: cout << d5.at(i) << " "; 101: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 103: int a6[] = {2, 4, 6, 8, 10, 12, 14, 16, 18, 20}; 104: deque<int> d6(a6, a6+10); 105: cout << "\nFor d6 we have ..."; 106: cout << "\nSize = " << d6.size(); 107: cout << "\nContents: "; 108: for(deque<int>::size_type i=0; i<d6.size(); i++) 109: cout << d6.at(i) << " "; 110: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 112: d5.assign(d6.begin()+2, d6.begin()+5); 113: cout << "\nNow we perform d5.assign(d6.begin()+2, d6.begin()+5). " 114: "\nThen for d5 we have ..."; 115: cout << "\nSize = " << d5.size(); 116: cout << "\nContents: "; 117: for(deque<int>::size_type i=0; i<d5.size(); i++) 118: cout << d5.at(i) << " "; 119: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 121: d5.assign(d6.begin()+1, d6.begin()+8); 122: cout << "\nNow we perform d5.assign(d6.begin()+1, d6.begin()+8). " 123: "\nThen for d5 we have ..."; 124: cout << "\nSize = " << d5.size(); 125: cout << "\nContents: "; 126: for(deque<int>::size_type i=0; i<d5.size(); i++) 127: cout << d5.at(i) << " "; 128: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 129: }