1.find 運算
find 運算是基于迭代器的,因此可在任意容器中使用相同的find函數查找值。
下面舉些簡單例子:
#include 
<iostream>
#include 
<algorithm>
#include 
<list>
#include 
<iterator>
using namespace std;
int main()

list 
<int> l;
int t;
while(cin>>t)
l.push_front(t);
int se;
cout
<<"輸入你想要查找的數:"<<endl;
cin.clear();
cin.sync();
cin
>> se;
list
<int> :: const_iterator result = find (l.begin

(),l.end(),se);
cout
<<"the value "<<se<< (result == l.end()? " is not

present
""is present")<<endl;
return 0;
}

類似地,由于指針的行為與作用在內置數組的迭代器一樣,因此可用find來搜索數組:
#include 
<iostream>
#include 
<algorithm>
using namespace std;
int main()

int a[] = {1,2,3,4,5};
int b = 7
int *= find(a,a+5,b);
cout
<<"the value "<<b<<(p==a+5? "is not present":"is

present
")<<endl;
return 0;
}