簡單的程式詮釋C++ STL演算法系列之五:find_first_of

來源:互聯網
上載者:User

        C++STL的非變易演算法(Non-mutating algorithms)是一組不破壞操作資料的模板函數,用來對序列資料進行逐個處理、元素尋找、子序列搜尋、統計和匹配。

        find_first_of演算法用於尋找位於某個範圍之內的元素。它有兩個使用原型,均在迭代器區間[first1, last1)上尋找元素*i,使得迭代器區間[first2, last2)有某個元素*j,滿足*i ==*j或滿足二元謂詞函數comp(*i, *j)==true的條件。元素找到則返回迭代器i,否則返回last1。

函數原型:

template<class ForwardIterator1, class ForwardIterator2>   ForwardIterator1 find_first_of(      ForwardIterator1 _First1,       ForwardIterator1 _Last1,      ForwardIterator2 _First2,       ForwardIterator2 _Last2   );template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>   ForwardIterator1 find_first_of(      ForwardIterator1 _First1,       ForwardIterator1 _Last1,      ForwardIterator2 _First2,       ForwardIterator2 _Last2,      BinaryPredicate _Comp   ); 

範例程式碼:

#include <algorithm>#include <iostream>using namespace std;int main(){const char* strOne = "abcdef1212daxs";const char* strTwo = "2ef";const char* result = find_first_of(strOne, strOne + strlen(strOne), strTwo, strTwo + strlen(strTwo));cout << "字串strOne中第一個出現在strTwo的字元為:" << *result << endl;return 0;}

*******************************************************************************************************************************

C++經典書目索引及資源下載:http://blog.csdn.net/jerryjbiao/article/details/7358796

********************************************************************************************************************************

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.