fork download
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4.  
  5. struct AppleClass
  6. {
  7. string id;
  8. int price;
  9.  
  10. bool operator<(const AppleClass& o) const
  11. {
  12. return price > o.price;
  13. }
  14. };
  15.  
  16. int main()
  17. {
  18. set<AppleClass> myapples;
  19. myapples.insert({"apple1", 500});
  20. myapples.insert({"apple1", 600});
  21. myapples.insert({"apple1", 400});
  22.  
  23. auto e = myapples.find({"apple13", 500});
  24. cout << e->id << "," << e->price << endl;
  25.  
  26. for (auto& apple : myapples)
  27. {
  28. cout << apple.id << "," << apple.price << endl;
  29.  
  30. }
  31. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
apple1,500
apple1,600
apple1,500
apple1,400