我想看看字符串中是否存在某个字符
我正在用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
首先学习在文档中进行搜索,例如: 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 ... )
您可以使用 find_first_of
You can use find_first_of
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()
看看 string::find
Take a look at string::find