#include #include #include using namespace std; void display_size_capacity(const vector & v) //post: displays the size and capacity of a vector { cout << "size is " << v.size() << " and the capacity is " << v.capacity() << endl; } void print (const vector & v) { int i; for (i=0; i < v.size(); i++) { cout << v[i] << endl; } } int main() { vector words; cout << "created an empty vector: "; display_size_capacity(words); // vector words(5); //also try with having a non-empty string as an initial value // cout << "created a vector with 5 elements: "; // display_size_capacity(words); // words.reserve(5); // cout << "reserved 5 words: "; // display_size_capacity(words); string str; while (cin >> str) { words.push_back(str); cout << "added " << str << ": "; display_size_capacity(words); } /* //pop_back example int currentSize = words.size(); for (int i=0; i < currentSize; i++) { words.pop_back(); display_size_capacity(words); } */ print (words); display_size_capacity(words); return 0; }