Help with string array

I am trying to make my program detect a user inputed string from a list of strings stored in an array. Then respond to it in a certain way using an if statement.

This is my first time using C++.

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 <string>
using namespace std;

int main(){

	string input;

	// Command list.
	const int SIZE = 3;
	string commands [SIZE] = { "/run", "/add", "/delete" };

	cout << "Welcome to ProgramName, please enter a command." << endl;
	cin  >> input;

	for(int i=0; i<SIZE; i++){
		if(input==commands[i])
			cout << "Command recognized: " << commands[i] << endl;
	}

	system("pause");
	return(0);
}


I believe I am having an error with the if statement. It saying that the string input needs to be a bool?
Last edited on
You need to use == if you want comparison, as = is assignment.
Thank you! That was simple.. -__-"
Last edited on
Topic archived. No new replies allowed.