What operator should??

Jun 6, 2013 at 5:00am
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 Jun 6, 2013 at 5:01am
Jun 6, 2013 at 5:09am
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
Jun 6, 2013 at 6:09am
or you could just use the find member of the string class
http://www.cplusplus.com/reference/string/string/find/
Jun 6, 2013 at 6:53am
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!
Jun 6, 2013 at 7:36am
Thanks guys for the help. Got it!
Topic archived. No new replies allowed.