Or login with:
#include<algorithm> template <class InputIterator, class Type> InputIterator find( InputIterator first, InputIterator last, const Type& val );Parameters:
| Parameter | Description |
|---|---|
| first | An input iterator addressing the position of the first element in the range to be searched for the specified value |
| last | An input iterator addressing the position one past the final element in the range to be searched for the specified value |
| val | The value to be searched for |
#include <algorithm> #include <vector> int main() { int n1 = 3; int n2 = 5; std::vector<int> v{0, 1, 2, 3, 4}; std::vector<int>::iterator result1, result2; result1 = std::find(v.begin(), v.end(), n1); result2 = std::find(v.begin(), v.end(), n2); if (result1 != v.end()) std::cout <<"v contains: "<<n1<<"\n"; else std::cout <<"v does not contain: "<<n1<<"\n"; if (result2 != v.end()) std::cout <<"v contains: "<<n2<<"\n"; else std::cout <<"v does not contain: "<<n2<<"\n"; return 0; }
You must login to leave a messge