// Oldham, Jeffrey D. // 2000 Jan 29 // CS1321 #include #include // has EXIT_SUCCESS #include // has vector #include // has string int main() { std::vector v; // creates an empty vector that can // hold int's std::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 << "Is the vector of size 4 empty? "; if (w.size() == 0) // w.size() returns number of position // in w. Note these positions need // not be filled with elements. cout << "yes.\n"; else cout << "no.\n"; w[0] = "hello"; // store a string at vector's first position 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 cout << "w[0] = " << w[0] << ".\n"; return EXIT_SUCCESS; }