|
-
February 20th, 2009, 05:21 AM
#1
Please help how to create a C++ stl map that takes a comparison function?
This is what I tried but when I retrieve from the map I get nothing:
#include <iostream>
#include <map>
using namespace std;
struct strCompare
{
strCompare(){}
bool operator()(const std::string& str1,const std::string& str2)const
{
return str1.compare(str2)<=0;
}
};
typedef std::map<std::string, std::string, strCompare> mymap;
int main()
{ mymap m = mymap();
m["abc"]="def";
std::cout<<m["abc"];
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|