1. 程式人生 > >C++string中的查詢函式find與find_first_of函式的區別

C++string中的查詢函式find與find_first_of函式的區別

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

find_first_of函式:在母串上從指定位置開始查詢,如果遇到的字元與目標串中任意字元相同,則查詢成功,返回該字元的位置。

string (1)  
size_t find (const string& str, size_t pos = 0) const noexcept;
c-string (2)    
size_t find (const char* s, size_t pos = 0) const;
buffer (3)  
size_t find (const char* s, size_t pos, size_type n) const
; character (4) size_t find (char c, size_t pos = 0) const noexcept;

find函式:在母串上從指定位置開始,查詢字元或字串。當查詢字串時,要保證目標串為母串的子串。下面是cplusplus.com中的描述:

Notice that unlike member find_first_of, whenever more than one character is being searched for, it is not enough that just one of these characters match, but the entire sequence must match.

注:rfind與find使用方法類似;find_last_of、find_first_not_of、find_last_not_of與find_first_of使用方法類似。

相關推薦

C++string查詢函式findfind_first_of函式區別

string (1) size_t find_first_of (const string& str, size_t pos = 0) const noexcept; c-string (2) size_t find_first_of (co

C++STLvector容器 begin()end()函式、front()back()

begin函式: 函式原型: iterator begin(); const_iterator begin(); 功能: 返回一個當前vector容器中起始元素的迭代器。 end函式: 函式原型: iterator end(); const_iterat

[C++]STLvector容器 begin()end()函式、front()back()的用法

    本部落格轉自http://blog.csdn.net/duan19920101/article/details/51679517 一、begin函式 函式原型: iterator begin(); const_iterator begin(); 功能: 返回一個當

C++STLvector容器 begin()end()函式、front()back()的用法

一、begin函式 函式原型: iterator begin(); const_iterator begin(); 功能: 返回一個當前vector容器中起始元素的迭代器。 二、end函式 函式原型: iterator end(); const_iterator end(

淺析C++string用於查詢find函式

總述:       以下所講的所有的string查詢函式,都有唯一的返回型別,那就是size_type,即一個無符號整數(按打印出來的算)。若查詢成功,返回按查詢規則找到的第一個字元或子串的位置;若查詢失敗,返回npos,即-1(打印出來為4294967295)。 1.

C++ stringfind()函式

1.string中find()返回值是字母在母串中的位置(下標記錄),如果沒有找到,那麼會返回一個特別的標記npos。(返回值可以看成是一個int型的數) #include<cstring> #include<cstdio> #inclu

C++string用於查找的find系列函數淺析

ace 規則 ret stream num 原因 目標 自己 查找字符 總述: 以下所講的所有的string查找函數,都有唯一的返回類型,那就是size_type,即一個無符號整數(按打印出來的算)。若查找成功,返回按查找規則找到的第一個字符或子串的位置;若查找失

c++ string的c_str()data()用法

#include <string> #include <iostream> int main( )  {    using namespace std;    string  str1 ( "Hello world" );    cout <

C++類的組合建構函式

首先看看建構函式的概念。在程式執行過程中,當遇到物件宣告語句時,程式會想作業系統申請一定的記憶體空間用於存放新建的物件。而編譯器不知道如何產生程式碼來實現初始化。所以C++做了一套物件初始化的機制,就是建構函式。 然後是類的組合中,當建立類的物件時,如果這個類

C語言兩個反正切函式atanatan2的區別

我們可以使用正切操作將角度轉變為斜率,那麼怎樣利用斜率來轉換為角度呢?可以利用斜率的反正切函式將他轉換為相應的角度.as中有兩個函式可以計算反正切,我們來看一下. 1、as中Math.atan() Math.atan()接受一個引數:用法如下: angel=Math.atan(slope)  angel為一

c++虛表指標虛擬函式詳解

1.c++類中的過載 看看下面的程式碼: #include <iostream> using namespace std; class Vehicle

C++ string的幾個小陷阱,你掉進過嗎?

stl 試題 賦值 clu ror ati world mod iostream C++開發的項目難免會用到STL的string。使用管理都比char數組(指針)方便的多。但在得心應手的使用過程中也要警惕幾個小陷阱。避免我們項目出bug卻遲遲找不到原因。1. 結構體中的

C#的結構體類的區別

nbsp display 分享 pan ron none 技術分享 初始 title (一) 語法定義上的區別,定義類使用關鍵字class 定義結構使用關鍵字struct (二) 在結構體中可以聲明字段,但是聲明字段的時候是不能給初始值的. C#中的結構體與類的區

JQfind()filter()的區別

區分 mon 我們 ima 1-1 nbsp image iter upload 剛開始學的時候,對於find()和filter()有點理不清楚,下面通過案例相信就可以很快的區分清楚   以下是代碼 find彈出的是 filter()彈出的是 下面我們

C語言的強符號弱符號

_weak 多個 obj china 很難 字節 whole sta dump 註意,強符號和弱符號都是針對定義來說的,不是針對符號的引用。 一、概述 在C語言中,函數和初始化的全局變量(包括顯示初始化為0)是強符號,未初始化的全局變量是弱符號。 對於它們,下列三條規則使用

random無法在C語言使用,randsrand種子

標題rand與srand之間的分析 1. 關於隨機數的使用: 下面我寫了一個簡單的數學題聯絡軟體: 程式碼如下: #include <stdio.h> #include "stdlib.h" int main(){ int a, b ,c; char d; whi

C++學習筆記 (六) ---- 多型虛擬函式

①、多型的概念 先上一個示例 #include <iostream> using namespace std; //基類People class People{ public: People(char *name, int age); void display(

C語言一維陣列二維陣列

int arr [4]  //定義了一個一維陣列,長度為4;說明以下三個分別是什麼型別; (1)arr //型別為int *,表示陣列元素首地址,即圖中箭頭指向的位置。 (2)arr+1 //型別為int *,表示陣列元素首地址+1,即圖中箭頭指向的位置。 (3)arr [0

c++ 11 顯式預設設定的函式和已刪除的函式 總結

今天在一個類中看到如下程式碼不是很懂,原來是c++11 新特性 RateTimer(const RateTimer&) = delete; //不可拷貝/不可賦值 RateTimer& operator=(const RateTimer&) = delete;

C++類的靜態成員靜態方法

C++中,若類的方法前加了static關鍵字,則該方法稱為靜態方法,反之為例項方法。靜態方法為類所有,可以通過物件來使用,也可以通過類來使用。但一般提倡通過類名來使用,因為靜態方法只要定義了類,不必建立類的例項就可使用。靜態方法只能呼叫靜態變數。 呼叫方式