目录

find_first_not_of

描述 (Description)

它在字符串中搜索与其参数中指定的任何字符都不匹配的第一个字符。

声明 (Declaration)

以下是std :: string :: find_first_not_of的声明。

size_t find_first_not_of (const string& str, size_t pos = 0) const;

C++11

size_t find_first_not_of (const string& str, size_t pos = 0) const noexcept;

C++14

size_t find_first_not_of (const string& str, size_t pos = 0) const noexcept;

参数 (Parameters)

  • str - 它是一个字符串对象。

  • len - 用于复制字符。

  • pos - 要复制的第一个字符的位置。

返回值 (Return Value)

没有

异常 (Exceptions)

如果抛出异常,则字符串中没有变化。

例子 (Example)

在下面的示例中,std :: string :: find_first_not_of。

#include <iostream>
#include <string>
#include <cstddef>
int main () {
   std::string str ("It looks for non-alphabetic characters...");
   std::size_t found = str.find_first_not_of("abcdefghijklmnopqrstuvwxyz ");
   if (found!=std::string::npos) {
      std::cout << "The first non-alphabetic character is " << str[found];
      std::cout << " at position " << found << '\n';
   }
   return 0;
}

样本输出应该是这样的 -

The first non-alphabetic character is I at position 0
↑回到顶部↑
WIKI教程 @2018