Guest User

Untitled

a guest
Apr 22nd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3.  
  4. int main()
  5. {
  6. std::set<int> my_set;
  7. my_set.insert(0x4A);
  8. my_set.insert(0x4F);
  9. my_set.insert(0x4B);
  10. my_set.insert(0x45);
  11.  
  12. for (std::set<int>::iterator it=my_set.begin(); it!=my_set.end(); ++it)
  13. std::cout << ' ' << char(*it); // ups the ordering
  14.  
  15. //int x = my_set[0]; // this causes a crash!
  16. }
  17.  
  18. std::set<int>::iterator it = my_set.begin();
  19. std::advance(it, n);
  20. int x = *it;
  21.  
  22. int x = *std::next(my_set.begin(), n);
  23.  
  24. auto it = my_set.begin();
  25. int first=0;
  26. if (it != my_set.end()) first = *it;
  27.  
  28. std:vector<std::string> my_set;
  29.  
  30. ...
  31.  
  32. std::string new_item("test");
  33.  
  34. auto range = std::equal_range(my_set.begin(),my_set.end(),new_item);
  35. if (range.first == range.second)
  36. my_set.insert(range.first,new_item);
  37.  
  38. std::set<int> my_set;
  39. my_set.insert(0x4A);
  40. my_set.insert(0x4F);
  41. my_set.insert(0x4B);
  42. my_set.insert(0x45);
  43.  
  44. int arr[my_set.size()];
  45.  
  46. set<int>::iterator it = my_set.begin();
  47. for (int i = 0; i < my_set.size(); i++) {
  48. arr[i] = *it;
  49. it++;
  50. }
  51. cout << arr[0];
Add Comment
Please, Sign In to add comment