how to erase element from multiset c 2b 2b

Solutions on MaxInterview for how to erase element from multiset c 2b 2b by the best coders in the world

showing results for - "how to erase element from multiset c 2b 2b"
Isabel
22 Jul 2016
1#include <iostream>
2#include <set>
3
4int main()
5{
6	std::multiset<int>ms;
7  	ms.insert(1);
8  	ms.insert(1);
9  	ms.insert(2);
10  	ms.insert(2);
11  	ms.insert(3);
12  	ms.insert(3);
13  	for(auto& it : ms) {
14		std::cout<<it<<' ';
15    }
16  	std::cout<<'\n';
17  	ms.erase(2); // erases all elements with value 2
18  	for(auto& it : ms) {
19		std::cout<<it<<' ';
20    }
21  	std::cout<<'\n';
22  	ms.erase(ms.begin()); // erases first element
23  	for(auto& it : ms) {
24		std::cout<<it<<' ';
25    }
26  	std::cout<<'\n';
27  	ms.erase(ms.find(3)); // erases only one element with value 3
28  	for(auto& it : ms) {
29		std::cout<<it<<' ';
30    }
31	return 0;
32}
33