class workbase //职工数据库
{
public:
worker workers[MAX];
int top;
friend class moneybase;
public:
workbase()
{
worker b;
top=-1;
fstream file("worker.txt",ios::in); //打开文件
while (1)
{
file.read((char *)&b,sizeof(b));
if (!file) break;
top++;
workers[top]=b;
}
file.close(); //关闭文件
}
~workbase() //析构函数, 将worker[]写到work.txt文件中
{
fstream file("worker.txt",ios::out);
for (int i=0;i<=top;i++)
{
if (workers[i].del==1)
file.write((char *)&workers[i],sizeof(workers[i]));
}
file.close();
}
onemoo
相关分类