Answers for "multiset c++"

C++
0

multiset c++

< Multisets > A multiset is a set that can have several copies of the same value. 
 C++ has the structures multiset and unordered_multiset that resemble set and
unordered_set. 
  
  multiset<int> s;
  s.insert(2);
  s.insert(2);
  s.insert(2);
  cout << s.count(2) << "\n"; // 3

- Erase removes all copies of a value from a multiset:
     s.erase(2);
     cout << s.count(2) << "\n"; // 0

- Erase only one element with value 2
     s.erase(s.find(2));
     cout << s.count(2) << "\n"; // 2
Posted by: Guest on June-24-2021

Browse Popular Code Answers by Language