日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

STL 之find,find_if,find_end,find_first_of

發布時間:2024/4/11 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 STL 之find,find_if,find_end,find_first_of 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

作用:用來在一個指定的區間中查找元素。


1,find, find_if

原型:

  • #include?<algorithm>??
  • template?<class?inputItr,class?size,class?Type>??
  • inputItr?find(inputItr?first,?inputItr?last,?const?Type&?searchValue);??
  • ??
  • template?<class?inputItr,?class?unaryPredicate>??
  • inputItr?find_if(inputItr?first,?inputItr?last,?UnaryPredicate?op);??

  • 示例代碼:

  • #include?<iostream>??
  • #include?<list>??
  • ??
  • #include?<string>??
  • #include?<numeric>??
  • #include?<iterator>??
  • #include?<vector>??
  • #include?<functional>??
  • ??
  • #include?<algorithm>??
  • ??
  • using?namespace?std;??
  • ??
  • int?main()?{??
  • ????char?cList[10]?=?{'a','i','C','d','e','f','o','H','u','j'};??
  • ????vector<char>?charList(cList,cList+10);??
  • ??
  • ????ostream_iterator<char>?screen(cout,?"?");??
  • ????cout?<<?"charList:"?<<?endl;??
  • ????copy(charList.begin(),charList.end(),screen);??
  • ????cout?<<?endl;??
  • ??
  • ????//?定義迭代器??
  • ????vector<char>::iterator?position;??
  • ????position?=?find(charList.begin(),charList.end(),'d');??
  • ??
  • ????if?(?position?!=?charList.end())???
  • ????{??
  • ????????cout?<<?"position?=?"?<<?(position?-?charList.begin())?<<?endl;???
  • ????}?else?{??
  • ????????cout?<<?"the?element?is?not?in?the?list"?<<?endl;??
  • ????}??
  • ??
  • ????position?=?find_if(charList.begin(),charList.end(),isupper);??
  • ????if?(?position?!=?charList.end())???
  • ????{??
  • ????????cout?<<?"position?=?"?<<?(position?-?charList.begin())?<<?endl;???
  • ????}?else?{??
  • ????????cout?<<?"the?element?is?not?in?the?list"?<<?endl;??
  • ????}??
  • ??
  • ????return?0;??
  • }??

  • 運行結果:

    charList:
    a i C d e f o H u j
    position = 3
    position = 2


    2,find_end,find_first_of

    聲明:

  • #include?<algorithm>??
  • template?<class?forwardItr1,class?forwardItr2>??
  • forwardItr1?find_end(forwardItr1?first1,?forwardItr1?last1,forwardItr2?first2,forwardItr2?last2);??
  • template?<class?forwardItr1,class?forwardItr2,class?binaryPredicate>??
  • forwardItr1?find_end(forwardItr1?first1,?forwardItr1?last1,forwardItr2?first2,forwardItr2?last2,binaryPredicate?op);??
  • ??
  • template?<class?forwardItr1,class?forwardItr2>??
  • forwardItr1?find_first_of(forwardItr1?first1,?forwardItr1?last1,forwardItr2?first2,forwardItr2?last2);??
  • template?<class?forwardItr1,class?forwardItr2,class?binaryPredicate>??
  • forwardItr1?find_first_of(forwardItr1?first1,?forwardItr1?last1,forwardItr2?first2,forwardItr2?last2,binaryPredicate?op);??

  • 示例代碼:

  • #include?<iostream>??
  • #include?<list>??
  • ??
  • #include?<string>??
  • #include?<numeric>??
  • #include?<iterator>??
  • #include?<vector>??
  • #include?<functional>??
  • ??
  • #include?<algorithm>??
  • ??
  • using?namespace?std;??
  • ??
  • int?main()?{??
  • ????int?list1[10]?=?{12,34,56,21,34,78,34,56,12,25};??
  • ????int?list2[2]?=?{34,56};??
  • ????int?list3[3]?=?{56,21,35};??
  • ????int?list4[5]?=?{33,48,21,34,73};??
  • ??
  • ????vector<int>?vecList1(list1,list1+10);???
  • ????vector<int>?vecList2(list2,list2+2);???
  • ????vector<int>?vecList3(list3,list3+3);???
  • ????vector<int>?vecList4(list4,list4+5);???
  • ??
  • ????vector<int>::iterator?localtion;??
  • ????ostream_iterator<int>?screen(cout,?"?");??
  • ??
  • ????cout?<<?"List1"?<<?endl;??
  • ????copy(list1,list1+10,screen);??
  • ????cout?<<?endl;??
  • ??
  • ????cout?<<?"List2"?<<?endl;??
  • ????copy(list2,list2+2,screen);??
  • ????cout?<<?endl;??
  • ??
  • ????//?find_end?查找最后一個匹配??
  • ????//?在vecList1?中查找vecList2??
  • ????localtion?=?find_end(vecList1.begin(),vecList1.end(),vecList2.begin(),vecList2.end());??
  • ????if?(localtion?!=?vecList1.end())??
  • ????{??
  • ????????cout?<<?"position?=?"?<<?(localtion?-?vecList1.begin())?<<?endl;??
  • ????}?else?{??
  • ????????cout?<<?"vecList2?is?not?in?list1"?<<?endl;??
  • ????}??
  • ??
  • ????cout?<<?"List3:"?<<?endl;??
  • ????copy(vecList3.begin(),vecList3.end(),screen);??
  • ????cout?<<?endl;??
  • ????localtion?=?find_end(vecList1.begin(),vecList1.end(),vecList3.begin(),vecList3.end());??
  • ????if?(localtion?!=?vecList1.end())??
  • ????{??
  • ????????cout?<<?"position?=?"?<<?(localtion?-?vecList1.begin())?<<?endl;??
  • ????}?else?{??
  • ????????cout?<<?"vecList3?is?not?in?list1"?<<?endl;??
  • ????}??
  • ??
  • ????cout?<<?"List4:"?<<?endl;??
  • ????copy(vecList4.begin(),vecList4.end(),screen);??
  • ????cout?<<?endl;??
  • ????//?find_first_of?首次出現的位置??
  • ????//?可以檢查兩個容器中元素是否相互包含??
  • ????localtion?=?find_first_of(vecList1.begin(),vecList1.end(),vecList4.begin(),vecList4.end());??
  • ????if?(localtion?!=?vecList1.end())??
  • ????{??
  • ????????cout?<<?"position?=?"?<<?(localtion?-?vecList1.begin())?<<?endl;??
  • ????}?else?{??
  • ????????cout?<<?"No?element?of?List4?is?in?list1"?<<?endl;??
  • ????}??
  • ????return?0;??
  • }??
  • 運行結果:

    List1
    12 34 56 21 34 78 34 56 12 25
    List2
    34 56
    position = 6
    List3:
    56 21 35
    vecList3 is not in list1
    List4:
    33 48 21 34 73
    position = 1

    總結

    以上是生活随笔為你收集整理的STL 之find,find_if,find_end,find_first_of的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 亚洲天天做 | 九九久久精品视频 | 林雅儿欧洲留学恋爱日记在线 | 秋霞网一区二区三区 | 水多多在线| 亚洲成人av一区 | av男人的天堂在线 | 中文字幕在线视频日韩 | 五月综合色 | 欧美一区二区免费在线观看 | 成人精品视频99在线观看免费 | 日日干狠狠干 | 成人国产精品久久 | 国产美女啪啪 | 青在线视频 | 强开小嫩苞一区二区三区网站 | 欧美黄页网站 | 国内精品久久久久久久久久久 | 日韩va| 午夜精华 | 四虎午夜影院 | 九九这里只有精品视频 | 99视频导航 | 久久精品综合 | 尹人在线视频 | 真实人妻互换毛片视频 | 国产一区二区免费看 | 少妇搡bbbb搡bbb搡小说 | 日韩不卡在线视频 | 成人一级在线 | 日本毛片在线 | 精品国产黄色 | 欧美国产一二三区 | 色撸撸av| 少妇太紧太爽又黄又硬又爽小说 | 国产老熟女一区二区三区 | 日韩av中文字幕在线免费观看 | 国产在线区 | 男插女青青影院 | 日本网站在线 | 欧美性xxxxx 亚洲特黄一级片 | 日韩视频免费观看高清完整版在线观看 | 欧美性大战xxxxx久久久 | 日本韩国免费观看 | 天天色宗合 | 国产娇小hdxxxx乱 | 在线观看黄色大片 | 91福利视频网站 | 围产精品久久久久久久 | 亚洲久久久久久久 | 在线观看国产 | 国产高清一二三区 | 一区二区91 | 国产自产在线 | 欧美人与性禽动交精品 | 亚洲一级免费视频 | 吃瓜网今日吃瓜 热门大瓜 色婷在线 | 人人综合网 | 欧美成人免费在线观看 | 久久99热这里只频精品6学生 | 国产精品久久久久久久久久免费看 | 久久久国产精华液999999 | 久久男人| 国产成人av网 | 久久靠逼视频 | 亚洲一区二区 | 三级小视频在线观看 | 色视频在线观看 | 免费看裸体网站视频 | 生活片av | 久久亚洲日本 | 波多野吉衣中文字幕 | 18成人在线观看 | 久热只有精品 | 亚洲精品久久久久久动漫器材一区 | 无码人妻一区二区三区在线视频 | 精品人妻少妇嫩草av无码 | 欧亚av| 欧美日韩精品区 | 91精品久久久久久久99蜜桃 | 午夜免费福利在线观看 | 欧美a v在线播放 | 欧美无砖砖区免费 | www.伊人久久 | 深夜福利麻豆 | 日本高清视频www夜色资源 | 日韩精品自拍偷拍 | 国产ts在线视频 | 人妖和人妖互交性xxxx视频 | 久色99 | 99在线精品视频免费观看20 | 亚洲欧美日韩专区 | 亚洲国产欧美一区二区三区深喉 | 日韩av手机在线免费观看 | 人妻无码一区二区三区久久99 | 欧美午夜不卡 | 日韩精品av一区二区三区 | 午夜精品久久久久久久99老熟妇 | 国产理论av |