Find a string in a string

Write your question here.
Ok so basically all I want to be able to do is have the user input something,and then check through whatever they typed to see if they typed a certain word and then if they did type that certain word, do something.
1
2
3
4
5
6
7
8
9
10
11
12
    vector <string> directions;
    directions.push_back("NORTH");
    directions.push_back("EAST");
    directions.push_back("SOUTH");
    directions.push_back("WEST");

    string input;
    cin >> input;
    if (//input has North){
        //do this
    }
    
thank you was looking for this too
Hope this is what you are looking for

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <vector>
using namespace std;

int main() {
	vector<string> directions;
	directions.push_back("NORTH");
	directions.push_back("EAST");
	directions.push_back("SOUTH");
	directions.push_back("WEST");

	string input;
	cin >> input;
	int flag = 1; // flag is set as false
	for (vector<string>::iterator it = directions.begin(); it < directions.end(); ++it) {
		if (input == *it) {
			flag = 0;
		}
	}
	if(flag == 0) cout << "success";
	else cout << "fail";
	return 0;
}
Mehakb that is almost what I am looking for, it does help but the problem is it only works if the person just types in north, south, east, west, they cant type "go north" or anything like that
Oh and could you also explain what the iterator does? Ive never used that command
Is it compulsory to use vector? If not then you can do it with string, as string has
str.find();
Topic archived. No new replies allowed.