find_first_not_of()

find_first_not_of()是C++語言中string類對象的成員函式。

基本介紹

  • 中文名:find_first_not_of()
  • 外文名:find_first_not_of()
  • 實質:函式
  • 功能:返回string::npos
函式簡介,函式套用舉例,

函式簡介

函式原型:
#include <string>
size_type find_first_not_of(const string &str,size_type index =0 )const;
size_type find_first_not_of(const Char* str,size_type index =0 )const;
size_type find_first_not_of(const Char* str,size_type index,size_type num )const;
size_type find_first_not_of(Char ch,size_type index =0 )const;
函式find_first_not_of()功能如下:
1.返回在字元串中首次出現的不匹配str中的任何一個字元的首字元索引, 從index開始搜尋, 如果全部匹配則返回string::npos。
2.從index開始起搜尋當前字元串, 查找其中與str前num個字元中的任意一個都不匹配的序列, 返回滿足條件的第一個字元索引, 否則返回string::npos。
3.返回在當前字元串中第一個不匹配ch字元的索引, 從index開始搜尋, 沒用收穫則返回string::npos。

函式套用舉例

#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("look for non-alphabetic characters...");
size_t found;
found=str.find_first_not_of("abcdefghijklmnopqrstuvwxyz ");
if (found!=string::npos)
{
cout << "First non-alphabetic character is " << str[found];
cout << " at position " << int(found) << endl;
}
return 0;
}

相關詞條

熱門詞條

聯絡我們