在vector查找某元素

#include<iostream>
#include<algorithm>
#include<vector>
using namespacestd;

vector<int>array(100);//整型的array數組

int main()
{
 
  array[20]=50;

 

   vector<int>::iterators=find(array.begin(),array.end(),50);第一個參數是array的起始地址,第二個參數是array的結束地址,第三個參數是需要查找的值

 

    if( s!=array.end())//找到
 
  cout<<*s<<endl;

 

    elsecout<<"notfind!"<<endl;
 
  system("pause");
 
   return0;
 
   
}

 

find()函數的定義:

template <class InputIterator, classT>InputIterator find( InputIterator first, InputIterator last, const T&value){    while (first != last && *first !=value)++first;    return first;  }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章