I offer you operator< and operator== for your structure, instead of overloading the global operator, I find it much cleaner; Example:
struct test { string key; string data; bool operator<(const test& rhs) const { return key < rhs.key; } bool operator==(const test& rhs) const { return key == rhs.key; } };
Now about your real problem - you pass the string to the find() function, but it only accepts structures of type test . To do this, add a constructor for automatic conversion, so the final structure will look like this:
struct test { string key; string data; test(const std::string& strKey = "", const std::string& strData = "") : key(strKey), data(strData) {} bool operator<(const test& rhs) const { return key < rhs.key; } bool operator==(const test& rhs) const { return key == rhs.key; } };
Then passing the string to find() will automatically call the constructor and create a temporary test structure containing only the corresponding key. Note that in this special case, the constructor should not be explicit declared.
Mephane
source share