1: //list02.cpp 3: #include <iostream> 4: #include <string> 5: #include <list> 6: using namespace std; 8: int main() 9: { 10: cout << "\nThis program illustrates the list member functions " 11: "empty() and size()."; 12: cout << "\nPress Enter to continue ... "; cin.ignore(80, '\n'); 14: //Create an empty list 15: list<int> lst1; 16: cout << "\nSize of lst1: " << lst1.size(); 17: if (lst1.empty()) 18: cout << "\nThe list lst1 is empty.\n"; 19: else 20: { 21: cout << "\nContents of lst1: "; 22: list<int>::iterator p_i = lst1.begin(); 23: while (p_i != lst1.end()) cout << *p_i++ << " "; 24: cout << endl; 25: } 26: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 28: //Create a list using pointers to an integer array 29: int a[] = {2, 4, 6, 8, 10, 12}; 30: list<int> lst2(a, a + sizeof(a)/sizeof(int)); 31: cout << "\nSize of lst2: " << lst2.size(); 32: if (lst2.empty()) 33: cout << "\nThe list lst2 is empty.\n"; 34: else 35: { 36: cout << "\nContents of lst2: "; 37: list<int>::iterator p_i = lst2.begin(); 38: p_i = lst2.begin(); 39: while (p_i != lst2.end()) cout << *p_i++ << " "; 40: cout << endl; 41: } 42: cout << "Press Enter to continue ... "; cin.ignore(80, '\n'); 43: }