// // example of using STL "vector" template class // // input: none. // output: results of calling some functions. // // Oldham, Jeffrey D. // 2000 Jan 29 // CS1321 // Modified by: // Massingill, Berna L. // 2001 Sep #include #include // has EXIT_SUCCESS #include // has vector #include // has string using namespace std; int main() { vector v; // Creates an empty vector that can // hold int's. vector w(4); // Creates a vector that can hold up // to four strings. We can also // enlarge or shrink it as needed. cout << "Is the empty vector empty? "; if (v.empty()) // v.empty() returns a bool. cout << "yes.\n"; else cout << "no.\n"; cout << "The size of a vector declared with 4 elements is "; cout << w.size() << ".\n"; // w.size() returns number of position // in w. Note these positions need // not be filled with elements. w[0] = "hello"; // Store a string at vector's first position. cout << "This should be hello: " << w[0] << ".\n"; v.push_back(7); // Grow vector one larger, placing 7 // in the new position. v.push_back(13); // Add another element. cout << "This should be 13: " << v[1] << endl; v.pop_back(); // Shrink the vector by one position. return EXIT_SUCCESS; }