public member function
<string>

std::basic_string::find_first_not_of

string (1)
size_type find_first_not_of (const basic_string& str, size_type pos = 0) const;
c-string (2)
size_type find_first_not_of (const charT* s, size_type pos = 0) const;
buffer (3)
size_type find_first_not_of (const charT* s, size_type pos, size_type n) const;
character (4)
size_type find_first_not_of (charT c, size_type pos = 0) const;
string (1)
size_type find_first_not_of (const basic_string& str, size_type pos = 0) const noexcept;
c-string (2)
size_type find_first_not_of (const charT* s, size_type pos = 0) const;
buffer (3)
size_type find_first_not_of (const charT* s, size_type pos, size_type n) const;
character (4)
size_type find_first_not_of (charT c, size_type pos = 0) const noexcept;
在字串中查詢不匹配的字元
basic_string 中搜索第一個與其引數中指定的任何字元都不匹配的字元。

指定 pos 時,搜尋僅包括位置 pos 或之後的字元,忽略該字元之前可能出現的任何字元。

該函式使用traits_type::eq來確定字元的等價性。

引數

str
另一個 basic_string,其中包含要在搜尋中使用的字元集。
pos
搜尋中要考慮的字串中第一個字元的位置。
如果大於字串長度,則該函式永遠找不到匹配項。
注意:第一個字元用值表示0(不是1): 一個值為0表示搜尋整個字串。
s
指向字元陣列的指標。
如果指定了引數n(3),則陣列中的前n個字元用於搜尋。
否則(2),期望一個以空字元結尾的序列:用於搜尋的字元序列的長度由第一個出現的空字元確定。
n
要搜尋的字元值的數量。
c
要搜尋的單個字元。

charTbasic_string 的字元型別(即,它的第一個模板引數)。
成員型別size_type是一種無符號整型型別。

返回值

第一個不匹配字元的位置。
如果未找到此類字元,則該函式返回 basic_string::npos

成員型別size_type是一種無符號整型型別。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// string::find_first_not_of
#include <iostream>
#include <string>

int main ()
{
  std::string str ("look for non-alphabetic characters...");

  std::string::size_type 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 - at position 12


複雜度

未指定,但通常與length()-pos乘以要匹配的字元數成線性關係(最壞情況)。

迭代器有效性

沒有變化。

資料競爭

該物件被訪問。

異常安全

如果已知s未指向足夠長的陣列,會導致未定義行為
否則,該函式永遠不會丟擲異常(無丟擲保證)。

另見