////////////////////////////////////////
// 2018/04/28 14:33:26
// set-erase
// removes elements
#include <iostream>
#include <set>
using namespace std;
void print(set<int, less<int>> &s){
set<int, less<int>>::iterator it;
for (it = s.begin(); it != s.end(); it++){
cout << *it << " ";
}
cout << endl;
}
int main(){
int ary[] = { 1, 2, 3, 2, 3, 4, 8, 2, 5, 6 };
set<int, less<int>> s;
s.insert(ary, ary + 10);
print(s);
// erase '2'
s.erase(2);
print(s);
set<int, less<int>>::iterator it;
// Searches the container for an element equivalent to val and
// returns an iterator to it if found, otherwise it returns an
// iterator to set::end.
it = s.find(5);
// erase '5'
s.erase(it);
print(s);
it = s.find(4);
// erase from it to the end of set
s.erase(it, s.end());
print(s);
return 0;
}
/*
OUTPUT:
1 2 3 4 5 6 8
1 3 4 5 6 8
1 3 4 6 8
1 3
*/