This time I'm able to show a complete code:
#include <unordered_map>
#include <iostream>
#include <stdlib.h>
using namespace std;
bool mystrcmp(const char *s1, const char *s2) {
int i = 0;
do {
if(s1[i] != s2[i])
return false;
} while(s1[i++] != '\0');
return true;
}
struct eqstr
{
bool operator()(const char* s1, const char* s2) const
{
return mystrcmp(s1, s2);
}
};
int main(void) {
char buffer[5] = {'h', 'e', 'd', 'e', '\0'};
unordered_map<char *, int , hash<char *> , eqstr> int_from_symbols;
int_from_symbols["hede"] = 1;
int_from_symbols["hodo"] = 2;
unordered_map<char *, int , hash<char *> , eqstr>::const_iterator it = int_from_symbols.find(buffer);
eqstr myeq;
if(myeq("hede",buffer))
fprintf(stderr, "no problem here\n");
if(it == int_from_symbols.end())
fprintf(stderr, "dammit\n");
else fprintf(stderr, "%d\n", int_from_symbols[buffer]);
return 0;
}
This outputs:
no problem here
dammit
Any idea what's going on?
Thanks in advance,,
Onur