infile.close();
ofstream outfile("f1.txt",ios::out); if(!outfile) { cerr<<" open error"<<endl; exit(1); //退出程序 }
//----将数组存取的信息输出到文件中去---- for(i=0;i<N;i++) { if(i!=k) { outfile<<num[i]<<" "; outfile<<name[i]<<" "; outfile<<sex[i]<<" "; outfile<<politic[i]<<" "; outfile<<address[i]<<" "<<endl; } }
outfile.close(); N=N-1;
cout<<"已删除成功!"<<endl; }
void student::change() {
int i,k;
int num[M];
string name[M],sex[M],politic[M],address[M]; ifstream infile("f1.txt",ios::in); if(!infile) { cerr<<" open error"<<endl; exit(1); }
for(i=0;i<N;i++) { cout<<" "; infile>>num[i]; cout<<setw(9)<<num[i]; infile>>name[i]; cout<<setw(9)<<name[i]; infile>>sex[i];