C++ 我想查看字符串中是否存在字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3300743/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 12:35:23  来源:igfitidea点击:

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

c++stringcharacter

提问by Cissmayazz

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.

我正在用 C++(典型游戏)编写一个程序,您需要猜测一个字母,然后它会检查它是否存在于字符串中。

For example

例如

Secret String: I like to program.

秘弦:我喜欢编程。

Guess1: 'a'

猜一:'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)

我正在使用 std::string (强制性)

Any help is appreciated!

任何帮助表示赞赏!

回答by Scharron

Begin by learning searching in a documentation like : http://www.cplusplus.com/reference/string/string/. (Hint : you want to "find" something ... )

首先学习在文档中搜索,例如:http: //www.cplusplus.com/reference/string/string/。(提示:你想“找到”一些东西......)

回答by JRL

You can use find_first_of

您可以使用find_first_of

回答by Amardeep AC9MF

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

std::string 中有几种方法可以提供帮助:

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

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

回答by JLWarlow

Take a look at string::find

看一下string::find