Finds the element in the given range of numbers. 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.
Function Template :
InputIterator find (InputIterator first, InputIterator last, const T& val)
Input iterators to the initial and final positions in a sequence. The range
searched is [first,last), which contains all the elements between first and
last, including the element pointed by first but not the element pointed by last.
Value to be search in the range
Return Value :
An iterator to the first element in the range that compares equal to val.
If no elements match, the function returns last.
Input : 10 20 30 40 Output : Element 30 found at position : 2 (counting from zero) Input : 8 5 9 2 7 1 3 10 Output : Element 4 not found.
Original vector : 10 20 30 40 Element 30 found at position : 2 (counting from zero)
This article is contributed by Sachin Bisht. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- How to iterate over the elements of an std::tuple in C++
- How to access private/protected method outside a class in C++
- lvalues references and rvalues references in C++ with Examples
- Difference between cout and std::cout in C++
- C++ program to check whether a String is a Pangram or not
- Difference between pair in Multiset and Multimap in C++ STL
- How to use unordered_map efficiently in C++
- Header files in C/C++ with Examples
- C++ Program for the Fractional Knapsack Problem
- Trigraphs in C++ with Examples
- Difference Between DART and C++
- How to fix auto keyword error in Dev-C++
- Lexicographical smallest number after at most K consecutive swaps
- Important functions of STL Components in C++
- Array of Structures vs. Array within a Structure in C/C++
Improved By : dietrichflo68