我想看看字符串中是否存在某个字符

发布于 2024-09-10 18:47:29 字数 232 浏览 2 评论 0原文

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

例如

秘密字符串:我喜欢编程。

猜测 1:'a'

显示: 。 .... .. .....a...

等等,

但我不知道如何查看一个字符是否在这个秘密字符串中。

我正在使用 std::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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

oО清风挽发oО 2024-09-17 18:47:29

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

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

小忆控 2024-09-17 18:47:29

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

find()
rfind()
find_first_of()
find_last_of()
子字符串()

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文