函数

C11标准链接:http://www.cplusplus.com/reference/string/string/find_first_of/?kw=string%3A%3Afind_first_of

C++中的定义
**

  1. //string (1)
  2. size_t find_first_of (const string& str, size_t pos = 0) const noexcept;
  3. //c-string (2)
  4. size_t find_first_of (const char* s, size_t pos = 0) const;
  5. //buffer (3)
  6. size_t find_first_of (const char* s, size_t pos, size_t n) const;
  7. //character (4)
  8. size_t find_first_of (char c, size_t pos = 0) const noexcept;

功能

查找子串在母串中首次出现的位置

使用

  1. string s("abcdABCD123");
  2. string::size_type position = s.find_first_of("123");

例子说明

  1. # include<iostream>
  2. # include<algorithm>
  3. using namespace std;
  4. int main(void)
  5. {
  6. ////find函数返回类型 size_type
  7. string s("abcdABCD123");
  8. string::size_type position;
  9. //find 函数返回 AB 在 s 中的下标位置
  10. position = s.find_first_of("123");
  11. printf("s.find_first_of(\"123\") is :%d\n", position);
  12. }