1: //list14.cpp 3: #include <iostream> 4: #include <string> 5: #include <list> 6: using namespace std; 8: int main() 9: { 10: cout << "\nThis program illustrates the swap() member function " 11: "for list objects."; 12: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 14: list<int> lst1(5, 5); 15: cout << "\nFor lst1 we have:"; 16: cout << "\nSize = " << lst1.size(); 17: cout << "\nContents: "; 18: list<int>::iterator p = lst1.begin(); 19: while (p!= lst1.end()) cout << *p++ << " "; 20: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 22: list<int> lst2(10, 10); 23: cout << "\nFor lst2 we have:"; 24: cout << "\nSize = " << lst2.size(); 25: cout << "\nContents: "; 26: p = lst2.begin(); 27: while (p!= lst2.end()) cout << *p++ << " "; 28: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 30: cout << "\nNow we swap lst1 and lst2 with lst1.swap(lst2) and redisplay."; 31: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 33: lst1.swap(lst2); 34: cout << "\nFor lst1 we have:"; 35: cout << "\nSize = " << lst1.size(); 36: cout << "\nContents: "; 37: p = lst1.begin(); 38: while (p!= lst1.end()) cout << *p++ << " "; 39: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 40: cout << "\nFor lst2 we have:"; 41: cout << "\nSize = " << lst2.size(); 42: cout << "\nContents: "; 43: p = lst2.begin(); 44: while (p!= lst2.end()) cout << *p++ << " "; 45: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 46: }