0

This is what my vector starts as:

vector<string> inventory;
inventory.push_back("sword");
inventory.push_back("armor");

the player of this game will be able to choose two of three items with this code block:

while(paid < 2)
{
    cout << "choice: ";
    cin >> equip;
    ++paid;
    inventory.insert(inventory.begin(), equip);
}

if(paid == 2)
{
    cout << "\nYou are out of money\n";
}

then there is a character that will interact with one of the inventory items if you purchased it.

if((bazaar == "woman") || (bazaar == "WOMAN"))
{
    cout << "you approach the woman, and she gives you a look.";

    if(...)
    {

    }
}

in that second if statement, I want to be able to check for a string in the inventory vector, and have two separate things happen, depending on whether or not that string is in the vector somewhere.

(as a side note, this is code for a text based game played in the console window)

LogicStuff
  • 19,397
  • 6
  • 54
  • 74
Ben D.
  • 3
  • 3

1 Answers1

0
if(std::find(inventory.begin(), inventory.end(), std::string("sword")) != inventory.end())
    ...

do not forget to include <algorithm>

ixSci
  • 13,100
  • 5
  • 45
  • 79