⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agtbouns.cpp

📁 学习过C++程序设计语言(也就是说学习过Template)
💻 CPP
字号:
/////////////////////////////////////////////////
// 运行 cpl.bat 编译,生成 a.exe 文件,运行它。
// Write by MMT Studio
// 2005.01.14
/////////////////////////////////////////////////

#include <iostream>
#include <string>
#include <fstream>
#include <map>

using namespace std;
typedef map <string, double>::const_iterator CIT;

void main()
{
	map <string, double> bonuses;
	string agent;
	double bonus=0;

	ifstream bonusfile("bonuses.dat");
	if(!bonusfile)
	{
		// 报告出错信息并终止程序
		cout<<"open file error!"<<endl;
		exit(-1);
	}

	while (bonusfile >> agent >> bonus)
	{
		bonuses[agent]+=bonus;// 累加每个代理的奖金
	}

	// 显示 map 中的值,已经汇总
	for(CIT p=bonuses.begin(); p!=bonuses.end(); ++p)
	{
		cout << p->first <<'\t' << p->second <<endl;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -