#include#include #include int main() { std::vector v = {1, 2, 3, 4, 5}; auto it = std::find(v.begin(), v.end(), 3); if (it != v.end()) { std::cout << "Element found: " << *it << std::endl; } else { std::cout << "Element not found!" << std::endl; } return 0; }
#includeIn this example, we use `std::find` to search for the character 'l' in a string. If the element is found, the program outputs the position of the first occurrence of the element in the range. The `std::find` function is part of the C++ standard library and is included in the `#include #include int main() { std::string s = "hello world"; auto it = std::find(s.begin(), s.end(), 'l'); if (it != s.end()) { std::cout << "Element found at position " << it - s.begin() << std::endl; } else { std::cout << "Element not found!" << std::endl; } return 0; }