< Previous | Contents | Next >
You can access the member functions of an array element by writing the array element, followed by the member selection operator, followed by the member function name. This sounds a bit complicated, but it’s not. Here’s an example:
cout << inventory[0].size() << " letters in it.\n";
The code inventory[0].size() means the program should call the size() member function of the element inventory[0]. In this case, because inventory[0] is "battle axe", the call returns 10, the number of characters in the string object.