源代码:
#include
#include
#include
struct worker
{
char name[30];
char department[30];
float basepay,allowance,total;
};
void main()
{
char filename[30]="paydata.txt";
struct worker data;
ofstream outstuf;
outstuf.open(filename,ios::out|ios::binary);
if(!outstuf) { cout<<"打开文件失败!"<
outstuf<<"这是一个和工人工资有关的文件.\n"<
char ch='N';
while(ch!='y'&&ch!='Y')
{
cout<<"请输入工人名字,工人住址及其基本工资和奖金:"<
cin>>data.name>>data.department>>data.basepay>>data.allowance;//插入数据
outstuf<
cout<<"是否结束输入?Y or N?"<
cin>>ch;
}
outstuf.close();
//以下为改动操作*********
ifstream instuf;
instuf.open(filename,ios::in|ios::binary);
if(!instuf) { cout<<"文件打开失败,程序退出!"<
instuf.clear();
int i=0;
while(!instuf.eof())
{
instuf>>data.name>>data.department>>data.basepay>>data.allowance>>data.total;
data.basepay=data.basepay+100;;
data.total=data.total+100;
cout<<"现在输出工人的名字、住址、基本工资、奖金、总共资金:"<
cout<
i++;
}
instuf.close();
}
阅读(1659) | 评论(0) | 转发(1) |