fork(1) download
  1. #include <set>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. struct test {
  6. std::string key;
  7. std::string data;
  8. };
  9.  
  10. bool operator<(const test& t, const std::string& str) { return t.key < str; }
  11. bool operator<(const std::string& str, const test& t) { return str < t.key; }
  12. bool operator<(const test& t1, const test& t2) { return t1.key < t2.key; }
  13. std::set<test, std::less<>> s;
  14.  
  15. int main() {
  16. test newmember;
  17. newmember.key = "key";
  18. newmember.data = "data";
  19. s.insert(newmember);
  20.  
  21. auto it = s.find("key");
  22. std::cout << it->key << ", " << it->data << std::endl;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 4148KB
stdin
Standard input is empty
stdout
key, data