#include#include int main () { std::multiset myset = {10,20,30,30,30,40,50}; // Erase all 30 myset.erase(30); for (auto it = myset.begin(); it != myset.end(); ++it) std::cout << *it << " "; } // Output: 10 20 40 50
#includeBoth examples use the multiset erase method, which belongs to the C++ Standard Library.#include int main () { std::multiset myset = {10,20,30,30,30,40,50}; // Erase all elements between 20 and 40 auto it = myset.lower_bound(20); auto it2 = myset.upper_bound(40); myset.erase(it, it2); for (auto it = myset.begin(); it != myset.end(); ++it) std::cout << *it << " "; } // Output: 10 40 50