#include <stdio.h>
#include <map>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
typedef struct studentinfo
{
int ID;
string strName;
bool operator < (studentinfo const & A) const
{
if (ID < A.ID )
return true;
if (ID == A.ID)
return strName.compare(A.strName) < 0;
return false;
}
}stu;
int main( )
{
//用学生信息映射分数
map<stu,int>mp;
studentinfo st;
st.ID = 1;
st.strName = "peter";
mp.insert(pair<stu,int>(st,90));
st.ID = 1;
st.strName = "jack";
mp.insert(pair<stu,int>(st,91));
map<stu,int>::iterator iter;
for(iter = mp.begin( ); iter != mp.end( ); iter++)
cout<<iter->first.ID<<" "<<iter->second<<" "<<iter->first.strName<<endl;
}
转载于:https://www.cnblogs.com/tangcong/archive/2011/07/28/2120476.html