STL容器map的一段代码

/ // 运行 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; } }

bonuses.dat中的数据为:

Bob 35 Bob 90 Jane 80.25 Sue 100 Jane 65.5

cpl.bat的内容如下:

cl agtbouns.cpp del a.exe rename agtbouns.exe a.exe

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值