读书人

stl map的第一个元素不能是一个自定义

发布时间: 2012-02-12 17:16:33 作者: rapoo

stl map的第一个元素不能是一个自定义的结构体对把?
#include <map>
#include <iostream>
using namespace std;

int main()
{
typedef struct {string cout; string name;} key;
map <key, int> info;
key key1;
key1.cout = "chinese ";
key1.name = "chendong ";
info.insert(make_pair(key1, 1));
return 0;
}


是不是不可以这样?

[解决办法]
自定义结构体要有:
bool operator <(const T& t) const
{
...
}

读书人网 >C++

热点推荐