What operator should??

My question is what operator should i use in my loops to tell if the char is in the string variable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16


string password;
password = "red";
char letter;

cout << "Plaese pick a letter" << endl;
cin >> letter;
if(letter ?? password)
{
	cout << "Correct letter" << endl;
}
else if(letter ?? password)
{
	cout << "Wrong letter" << endl;
}
Last edited on
you can define your own function:

bool isPresentIn (const char& c, const std::string& s);

or you can use c++ algorithm "find".
http://www.cplusplus.com/reference/algorithm/find/?kw=find
or you could just use the find member of the string class
http://www.cplusplus.com/reference/string/string/find/
I would probably try something like this

1
2
3
4
5
6

if (letter.find(password) != string::npos)
{
   cout << letter << " is in the password!" << endl;
}





but that is just me!
Thanks guys for the help. Got it!
Topic archived. No new replies allowed.