Reputation: 2195
I'm programming a program in C++ (typical game) in which you need to guess a letter and it will check if it is present in a string.
For example
Secret String: I like to program.
Guess1: 'a'
Display: . .... .. .....a...
Etc.
But i don't know how to see if a character is in this secret string.
I'm using std::string (obligatory)
Any help is appreciated!
Upvotes: 8
Views: 54412
Reputation: 17757
Begin by learning searching in a documentation like : http://www.cplusplus.com/reference/string/string/ . (Hint : you want to "find" something ... )
Upvotes: 19
Reputation: 19044
There are several methods in std::string that would help:
find() rfind() find_first_of() find_last_of() substr()
Upvotes: 6