#include#include int main() { std::set mySet = { 1, 2, 3, 4, 5 }; mySet.erase(3); for (auto it = mySet.begin(); it != mySet.end(); ++it) { std::cout << *it << " "; } return 0; } // Output: 1 2 4 5
#includeThis example uses the erase function to remove all elements in the set that are less than 10. The resulting set is then printed out to the console. Package Library: The std::set::erase function is part of the C++ Standard Library, which is included with most C++ compilers.#include int main() { std::set mySet = { 1, 5, 10, 15, 20 }; mySet.erase(mySet.begin(), mySet.find(10)); for (auto it = mySet.begin(); it != mySet.end(); ++it) { std::cout << *it << " "; } return 0; } // Output: 10 15 20