fork download
  1. // set::lower_bound/upper_bound
  2. #include <iostream>
  3. #include <set>
  4.  
  5. int main ()
  6. {
  7. std::set<int> myset;
  8. std::set<int>::iterator itlow,itup;
  9.  
  10. for (int i=1; i<10; i++) myset.insert(i*10); // 10 20 30 40 50 60 70 80 90
  11.  
  12. itlow=myset.lower_bound (30); // ^
  13. itup=myset.upper_bound (60); // ^
  14.  
  15. myset.erase(itlow,itup); // 10 20 70 80 90
  16.  
  17. std::cout << "myset contains:";
  18. for (std::set<int>::iterator it=myset.begin(); it!=myset.end(); ++it)
  19. std::cout << ' ' << *it;
  20. std::cout << '\n';
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5284KB
stdin
10
aba
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
geeksforgeeks
stdout
myset contains: 10 20 70 80 90