Cissmayazz
Cissmayazz

Reputation: 2195

I want to see if a character is present in a string

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

Answers (4)

John Warlow
John Warlow

Reputation: 2992

Take a look at string::find

Upvotes: 0

Scharron
Scharron

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

Amardeep AC9MF
Amardeep AC9MF

Reputation: 19044

There are several methods in std::string that would help:

find() rfind() find_first_of() find_last_of() substr()

Upvotes: 6

JRL
JRL

Reputation: 77995

You can use find_first_of

Upvotes: 8

Related Questions