find find_first_of 去呗、
时间: 2023-09-05 08:14:28 浏览: 35
好的,`find_first_of`是C++ STL中的一个字符串查找函数,用于在字符串中查找第一个出现指定字符集中的任何一个字符的位置。
它的函数原型如下:
```cpp
size_t find_first_of (const string& str, size_t pos = 0) const noexcept;
size_t find_first_of (const char* s, size_t pos, size_t n) const;
size_t find_first_of (const char* s, size_t pos = 0) const;
size_t find_first_of (char c, size_t pos = 0) const noexcept;
```
其中,第一个参数是要查找的字符集,可以是一个字符串或者一个字符,第二个参数是搜索起始位置,默认从字符串开头进行搜索。
这个函数返回查找到的第一个匹配字符集中的任何一个字符的位置,如果没有找到则返回 `string::npos`。
下面是一个简单的例子:
```cpp
#include<iostream>
#include<string>
using namespace std;
int main()
{
string s = "hello, world!";
size_t found = s.find_first_of("aeiou");
if (found != string::npos) {
cout << "Vowel found at position " << found << endl;
} else {
cout << "No vowel found." << endl;
}
return 0;
}
```
这个例子中,我们在字符串中查找第一个元音字母的位置。`find_first_of`函数返回了字符 `e` 的位置,因为它是字符集中第一个出现的元音字母。