function: Find value in range
Returns an iterator to the first element in the range [first,last) that compares equal to val. If no such element is found, the function returns last.
在cplusplus.com上的定义如上,很明了,不翻译占字数了
看一个例子
#include <iostream> // std::cout
#include <algorithm> // std::find
#include <vector> // std::vector
int main() {
// using std::find with array and pointer:
int myints[] = { 10, 20, 30, 40 };
int * p;
p = std::find(myints, myints + 4, 30);
if (p != myints + 4)
std::cout << "Element found in myints: " << *p << '\n';
else
std::cout << "Element not found in myints\n";
// using std::find with vector and iterator:
std::vector<int> myvector(myints, myints + 4);
std::vector<int>::iterator it;
it = find(myvector.begin(), myvector.end(), 30);
if (it != myvector.end())
std::cout << "Element found in myvector: " << *it << '\n';
else
std::cout << "Element not found in myvector\n";
return 0;
}
人,总是要有一点精神的,不是吗