fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. struct mypred {
  10. bool operator()(const char* a, const char *b) {
  11. return strcmp(a, b) < 0;
  12. }
  13. };
  14. std::map<const char *, int, mypred> m;
  15.  
  16. const char *j = "key";
  17. m.insert(std::make_pair(j, 5));
  18.  
  19. char *l = (char *)malloc(strlen(j)+1);
  20. strcpy(l, j);
  21.  
  22. printf("%s\n", "key");
  23. printf("%s\n", j);
  24. printf("%s\n", l);
  25.  
  26. // Check if key in map -> 0 if it is, 1 if it's not
  27. printf("%d\n", m.find("key") == m.end());
  28. printf("%d\n", m.find(j) == m.end());
  29. printf("%d\n", m.find(l) == m.end());
  30. }
  31.  
Success #stdin #stdout 0s 4976KB
stdin
Standard input is empty
stdout
key
key
key
0
0
0