// File: read3.C // // Sample program using STL list templates // Read the "spell" dictionary into a list #include #include #include #include // another STL "sequence container" #include // STL string template, like BString main() { list L ; string str ; int i ; // Get strings from stdin // while (cin >> str) { L.push_back(str) ; // append new string } // list allows efficient insertion at front L.push_front("0000") ; list::iterator it ; it = L.begin() ; for (i = 0 ; i < 4 ; i++) it++ ; // advance it 4 places L.erase(it) ; // list allows for efficient removal in the middle cout << "# of strings read = " << L.size() << endl ; // Using STL iterators // cout << "\nSTL iterators" << endl ; for (it = L.begin() ; it != L.end() ; it++) { cout << *it << endl ; } }