< Previous | Contents | Next >

Using the size() Member

Function

Next I display the number of items the hero has in his possession.

cout << "You have " << inventory.size() << " items.\n";

I get the size of inventory by calling the size() member function with inventory.size(). The size() member function simply returns the size of a vector. In this case, it returns 3.

Using Vectors 121