所谓修改删除文件a某位置的内容,其实是读打开文件a,再将‘a中修改删除位置之前的内容+修改删除的内容+a中修改删除位置之后的内容’保存到文件b,关闭文件a,删除文件a,将文件b改名为与之前文件a相同的名字,仅此而已。(或者把新建文件里面的信息再重新复制会源文件)
void huizong::shanchu_zhigongxinxi()//删除职工信息
{
system("color 8e");
cout<<"\t\t\t请输入要删除的职工的职工号:";
string a;
cin>>a;
ifstream ifs("D:\\123.text");
if(!ifs)//打开文件失败
{
ifs.close();
system("cls");
shanchuchazhao_shibai();
}
else
{
ofstream ofs;
char b[100];
ofs.open("D:\\1111.text",ios::trunc);
int falg=1;
int ff=0;
while(!ifs.eof())
{
ifs.getline(b,99,'\n');
if(b==a)
{
falg=0;
ifs.getline(b,99,'\n');
ifs.getline(b,99,'\n');
ifs.getline(b,99,'\n');
ifs.getline(b,99,'\n');
ifs.getline(b,99,'\n');
ifs.getline(b,99,'\n');
ifs.getline(b,99,'\n');
ifs.getline(b,99,'\n');
}
else
{
int g=8;
if(ff)
ofs<<endl;
ff=1;
ofs<<b;
while(g--)
{
ofs<<endl;
ifs.getline(b,99,'\n');
ofs<<b;
}
}
}
ifs.close();
ofs.close();
if(falg==0)
{
ofstream ofs;
ofs.open("D:\\123.text",ios::trunc);
ifstream ifs("D:\\1111.text");
char b[100];
int u=0;
while(!ifs.eof())
{
if(u!=0)
ofs<<endl;
ifs.getline(b,99,'\n');
ofs<<b;
u=1;
}
ofs.close();
ifs.close();
cout<<"\t\t\t删除成功\n\t\t\t继续删除请输入1,返回页面请输入2:";
int n;
cin>>n;
if(n==1)
{
system("cls");
shanchu_zhigongxinxi();
}
else
{
system("cls");
yemian();
}
}
else
{
system("cls");
shanchuchazhao_shibai();
}
}
}