Code:
#include <iostream>
#include <string>
#include <map>
#include <cstdio>
using namespace std;
struct CStrCmp : public binary_function <const char*, const char*, bool>
{
bool operator()(
const char* Left,
const char* Right
) const
{
return (strcmp(Left, Right) < 0);
}
};
int main(void)
{
map<char*, string, CStrCmp> str_map;
char hello_str[] = "Hello";
char test_str[] = "Test";
char boo_str[] = "boo!!";
str_map["Hello"] = string("Goodbye");
str_map["Test"] = string("Another Test");
str_map[boo_str] = string("You have been booed!");
cout << str_map["Hello"] << endl;
cout << str_map["Test"] << endl;
cout << str_map["boo!!"] << endl;
cout << str_map[hello_str] << endl;
cout << str_map[test_str] << endl;
cout << str_map[boo_str] << endl;
cout << str_map.count(hello_str) << endl;
cout << str_map.count(test_str) << endl;
cout << str_map.count("boo!!") << endl;
cout << str_map.count("Failure Test") << endl;
cin.get();
return 0;
}
I figured this out by noting that the default compare function is documented as less<Key>, then looking up the less class and basically copying it.