C++ multimap篇

前言:

项目开发中经常会用到的典型实例

multimap 案例

公司有销售2名,技术研发部2,财务部1.

人员信息有:姓名 年龄 电话 工资等

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

分部门显示员工信息

把age32修改成name12

#include
using namespace std;
#include"map"
#include"string"
class Person
{
public:
	string name;
	int    age;
	string tel;
	double saly;
};


void main11()
{
	Person p1, p2, p3, p4, p5;
	p1.name = "王大";
	p1.age = 31;

	p2.name = "王二";
	p2.age = 32;

	p3.name = "张三";
	p3.age = 33;

	p4.name = "李四";
	p4.age = 34;

	p5.name = "张五";
	p5.age = 35;
	multimapmap2;
	//销售部门
	map2.insert(make_pair("sale", p1));
	map2.insert(make_pair("sale", p2));
	//研发部门
	map2.insert(make_pair("dev", p3));
	map2.insert(make_pair("dev", p4));
	//采购部门
	map2.insert(make_pair("fin", p5));
	for (multimap::iterator it = map2.begin(); it != map2.end(); it++)
	{
		cout << it->first << "	" << it->second << endl;
	}
	cout << "遍历结束" << endl;

	cout << "开发部人数" << map2.count("开发");
	cout << "开发部员工信息" << endl;
	multimap::iterator it2 = map2.find("kaifa ");
	int tag = 0;
		while (it2 != map2.end()&&tagfirst << "	" << it2->second.name << endl;
			it2++;
			tag++;
		}
}
//把age32修改成name12
void main22()
{
	Person p1, p2, p3, p4, p5;
	p1.name = "";
	p1.age = 31;

	p2.name = "";
	p2.age = 32;

	p3.name = "";
	p3.age = 33;

	p4.name = "";
	p4.age = 34;

	p5.name = "";
	p5.age = 35;
	multimapmap2;
	//销售部门
	map2.insert(make_pair("sale", p1));
	map2.insert(make_pair("sale", p2));
	//研发部门
	map2.insert(make_pair("dev", p3));
	map2.insert(make_pair("dev", p4));
	//采购部门
	map2.insert(make_pair("fin", p5));
	for (multimap::iterator it = map2.begin(); it != map2.end(); it++)
	{
		cout << it->first << "	" << it->second << endl;
		if (it->second.age == 32)
		{
			it->second.name = "name32";
		}
	}
	cout << "遍历结束" << endl;
	for (multimap::iterator it = map2.begin(); it != map2.end(); it++)
	{
		cout << it->first << "	" << it->second << endl;

	}
}
void main()
{
	main11();
	main22();	


	cout << "hello..." << endl;
	system("pause");
	return;
}
展开阅读全文

页面更新:2024-05-29

标签:研发部   遍历   常会   前言   财务部   实例   典型   姓名   工资   年龄   员工   部门   案例   结束   科技   信息

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top