// File: read1.C // // Sample program using STL vector templates // Read the "spell" dictionary into a vector #include #include #include #include // STL auto-expanding array, "sequence container" #include // STL string template, like BString main() { vector V ; string str ; int i ; // Get strings from stdin // while (cin >> str) { V.push_back(str) ; // append new string } cout << "# of strings read = " << V.size() << endl ; // For loop syntax for iteration // for (i = 0 ; i < V.size() ; i++) { cout << V[i] << endl ; } // Using STL iterators // cout << "\nSTL iterators" << endl ; vector::iterator it ; for (it = V.begin() ; it != V.end() ; it++) { cout << *it << endl ; } }