下面这个程序运行不了,请各位高手帮我下,小生十分感谢!
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
struct Worker//定义一个结构体用以存放职工数据
{string num;
string name;
int base;
int extend;
int prize;
int deduct;
int actual;
};
int main()
{
Worker worker[2];//定义一个机构体数组,包含三个结构体对象
for(int i=0;i<3;i++)//输入职工相关数据
{
cin>>worker[i].num>>worker[i].name;
cin>>worker[i].base>>worker[i].extend>>worker[i].prize>>worker[i].deduct;
}
ofstream outfile("Salary.dat");//将职工数据写入文件
if(!outfile)
{cerr<<"open Salary.dat error!"<<endl;
exit(1);
}
for(int j=0;j<3;j++)
{
outfile<<worker[j].num<<' '<<worker[j].name<<' ';
outfile<<worker[j].base<<' '<<worker[j].extend<<' '<<worker[j].prize<<' '<<worker[j].deduct<<' ';
}
outfile.close();
ifstream infile("Salary.dat",ios::in|ios::_Nocreate);//从文件中读入职工数据并计算实际工资
if(!infile)
{cerr<<"open Salary.dat error!"<<endl;
exit(1);
}
for(int m=0;m<3;m++)
{
infile>>worker[m].num>>worker[m].name;
infile>>worker[m].base>>worker[m].extend>>worker[m].prize>>worker[m].deduct;
worker[m].actual=worker[m].base+worker[m].extend+worker[m].prize-worker[m].deduct;
}
infile.close();
cout<<"职工编号"<<'\t'<<"姓名"<<'\t'<<"基本工资"<<'\t'<<"加班工资"<<'\t'<<"奖金"<<'\t'<<"扣除"<<'\t'<<"时发工资"<<endl;//打印相关表格
for(int n=0;n<3;n++)
cout<<worker[n].num<<'\t'<<worker[n].name<<'\t'<<worker[n].base<<'\t'<<worker[n].extend<<'\t'<<worker[n].prize<<'\t'
<<worker[n].deduct<<'\t'<<worker[n].actual<<endl;
return 0;
}