Problem with string arrays?

I have been learning C++ for literally a week so sorry if this is a silly question.

I am trying to create one of the old style text adventures just for fun but I am having trouble with the verbs. So far I have created a function that reads input from the keyboard by way of a string, breaks the string down into its respective words and stores each word under a vector named sentence which can then be analysed.

The next idea is to compare the words in the vector with my list of command words (verbs) and act accordingly.

However I am having trouble with the verbs. I wanted to create a constant array called VERB where all the commands can be stored. However when I try to do this I keep getting errors. I've tried single and multiple dimension arrays but nothing seems to work.

Is it possible to create an array that can hold multiple strings so for example:

VERB[1] = "TAKE"
VERB[2] = "DROP" ....and so on

If so how do I go about doing this?

As an extension to this how do I then create a loop to compare the contents of the array with the first word (or for that matter any word) of my sentence vector? Do I have to use a pointer or will a simple if statement work?

Thanks for your help!
1
2
3
4
5
6
vector<string> verbs;
verbs.push_back("TAKE");
verbs.push_back("DROP");

if (find(verbs.begin(),verbs.end(),sentence[0])!=verbs.end())found the word;
else did not;
Topic archived. No new replies allowed.