< Previous | Contents | Next >
Calling Member Functions of an
Next I show the number of letters in the name of the first item in the hero’s inventory.
cout << inventory[0].size() << " letters in it.\n";
122 Chapter 4 n The Standard Template Library: Hangman
Just as with arrays, you can access the member functions of a vector element by writing the element, followed by the member selection operator, followed by the member function name. Because inventory[0] is equal to "battle axe", inventory[0].size() returns 10.