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

I am programming a C ++ program (regular game) in which you need to guess the letter and it will check if it is present in the string.

for example

Secret line: I like to program.

Guess1: 'a'

Display: ............ a ...

Etc.

But I do not know how to see if the character is in this secret line.

I use std :: string (required)

Any help is appreciated!

+7
c ++ string character
source share
4 answers

Start by looking at the documentation search, for example: http://www.cplusplus.com/reference/string/string/ . (Hint: you want to β€œfind” something ...)

+14
source share

You can use find_first_of

+8
source share

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

find () RFIND () find_first_of () find_last_of ()

+5
source share

Take a look at string :: find

0
source share

All Articles