Perhaps this is a duplicate but I did not find anything searching: When erase(value)
is called on std::multiset
all elements with the value found are deleted. The only solution I could think of is:
std::multiset<int>::iterator hit(mySet.find(5)); if (hit!= mySet.end()) mySet.erase(hit);
This is ok but I thought there might be better. Any Ideas ?
The multiset::clear() function is a built-in function in C++ STL which removes all elements from the multiset container. The final size of multiset container after removal is 0.
Multiset: They are associative containers that store multiple elements having equivalent values following a specific order. Following are the properties of multisets: Stores elements in sorted order. It allows the storage of multiple elements.
auto itr = my_multiset.find(value); if(itr!=my_multiset.end()){ my_multiset.erase(itr); }
I would imagine there is a cleaner way of accomplishing the same. But this gets the job done.
Try this one:
multiset<int> s; s.erase(s.lower_bound(value));
As long as you can ensure that the value
exists in the set. That works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With