c 中find函式的用法

2022-08-02 15:57:10 字數 843 閱讀 2644

find函式主要實現的是在容器內查詢指定的元素,並且這個元素必須是基本資料型別的。

查詢成功返回乙個指向指定元素的迭代器,即元素在容器中的下標,查詢失敗返回end迭代器。

標頭檔案

#include

函式實現

templateinputiterator find (inputiterator first, inputiterator last, 

const t&val)

return

last;

}

例1(vector)

#include #include #include using namespacestd;

intmain()

例2(set)

#include #include #include #include 

using namespacestd;

intmain()

1:set自身有個find函式,舉例如下:

#include #include #include #include 

using namespacestd;

intmain()

2:string自身有個find函式,沒有找到返回-1,舉例如下:

#include #include #include 

using namespacestd;

intmain()

C 中find函式用法

c 中stl裡提供了許多字串操作的函式,下面是字串查詢方面的部分函式用法簡介 1.find 查詢第一次出現的目標字串 include includeusing namespace std int main string s1 abcdef string s2 de int ans s1.find s...

c 中find函式的用法

1,返回字元 字串 在原來字串的中首次出現的下標位置 例 string s 1a2b3c4d5e6f7g8h9i1a2b3c4d5e6f7g8ha9i position s.find jk 2,返回flag 中任意字元 在s 中第一次出現的下標位置 flag c position s.find fi...

MATLAB中find函式的用法

find函式 查詢非零元素的索引和值 主要有下面5中用法,k find x x有三種情況 1 如果x為向量 行向量或者列向量 k為x中非零元素索引組成的向量。k的方向與x的方向相同。如果x為行向量,那麼k為行向量 2 如果x為多維陣列,k為x中非零元素線性索引組成的列向量 位置索引組成的列向量 線性...