用C++ 实现 STL multimap 案例

Multimap 案例:

//1个key值可以对应多个valude  =è分组 

//公司有销售部 sale (员工2名)、技术研发部 development (1人)、财务部 Financial (2人) 

//人员信息有:姓名,年龄,电话、工资等组成

//通过 multimap进行 信息的插入、保存、显示

//分部门显示员工信息 

 

 

Multimap.cpp

#include

#include

#include

#include

using namespace std;

 

class Employee

{

private:

char m_name[20];

int m_id;

public:

Employee(char *n,int id);

void print();

};

 

Employee::Employee(char *n,int id)

{

strcpy(m_name,n);

m_id =id;

}

void Employee::print()

{

cout << m_name << "  " << m_id << endl;

}

 

int main()

{

Employee s1("aa",10);

Employee s2("bb",11);

Employee s3("cc",12);

Employee s4("dd",13);

Employee s5("ee",14);

Employee s6("ff",15);

Employee s7("gg",16);

 

 

multimap m;

m.insert(pair("sale",s1));

m.insert(pair("sale",s2));

 

m.insert(make_pair("develop",s3));

m.insert(make_pair("develop",s4));

m.insert(make_pair("develop",s5));

 

m.insert(multimap::value_type("finacial",s6));

m.insert(multimap::value_type("finacial",s7));

 

 

if(m.empty())

{

cout << "map is empty!" << endl;

}

else

{

cout << "no empty" << endl;

}

 

int num = m.count("develop");

cout << "develop :" << num << endl;

 

multimap::iterator it = m.find("develop");

for(int i=0;i

{

it->second.print();

it++;

}

 

 

return 0;

}

 

你可能感兴趣的:(用C++ 实现 STL multimap 案例)