#include#include int main() { std::set myset = {1, 2, 3, 4, 5}; auto it = myset.find(3); // Search for element 3 in set if(it != myset.end()) // If element is found { std::cout << "Element found in set at position: " << std::distance(myset.begin(), it) << std::endl; } else // If element is not found { std::cout << "Element not found in set"; } return 0; }
#includeDescription: This example demonstrates the use of std::set and find() function to search for an element in a set. It initializes a set with vowels and then searches for an element 'z' in the set. As element 'z' is not present in the set, the function returns the end of the set. Package/Library: std::set is a part of the C++ Standard Library that comes with all C++ compilers. It is not specific to any external package or library.#include int main() { std::set myset = {'a', 'e', 'i', 'o', 'u'}; char ch = 'z'; auto it = myset.find(ch); // Searching for an element in the set if(it != myset.end()) // If element is found { std::cout << "Element found in set at position: " << std::distance(myset.begin(), it) << std::endl; } else // If element is not found { std::cout << "Element " << ch << " not found in set"; } return 0; }