#include <iostream>
#include <string>
usingnamespace std;
int main()
{
constint MAX_ITEMS = 10;
string inventory[MAX_ITEMS];
int numItems = 0;
inventory[numItems++] = "sword";
inventory[numItems++] = "armor";
inventory[numItems++] = "shield";
cout << "Your items:\n";
for (int i = 0; i < numItems; ++i)
{
cout << inventory[i] << endl;
}
cout << "\nYou trade your sword for a battle axe.";
inventory[0] = "battle axe";
cout << "\nYour items:\n";
for (int i = 0; i < numItems; ++i)
{
cout << inventory[i] << endl;
}
cout << "\nThe item name '" << inventory[0] << "' has ";
cout << inventory[0].size() << " letters in it.\n";
cout << "\nYou find a healing potion.";
if (numItems < MAX_ITEMS)
{
inventory[numItems++] = "healing potion";
}
else
{
cout << "You have too many items and can't carry another.";
}
cout << "\nYour items:\n";
for (int i = 0; i < numItems; ++i)
{
cout << inventory[i] << endl;
}
return 0;
}
I just don't understand what the dot (.) is used for. And the whole phrase.size() because every time he explains code like that he says "I called size() and blah blah blah" And I'm thinking "Wait he's called it but that's the first time he's used that in the program. If he's called it should be somewhere else in the program (Right? Or is that not necessarily true)".
Please help, I'm confused.