学籍.txt

来自「这是一个班级管理系统!希望大家能用上 !只要改动点就行」· 文本 代码 · 共 243 行

TXT
243
字号
void change()

{ int ch,p=0,l=0;

cout<<"请输入你要修改的学生的学号:"<<endl;

cin>>ch;

ifstream efile("student.txt",ios::nocreate);

while(efile.good())

{ efile.seekg(sizeof(information)*p);

if(efile.read((char *) &information,sizeof information))

{if(ch==information.getsno())

{ 

information.display();

ch=0;

information.change();

ofstream ffile("student.txt",ios::nocreate|ios::in);//以输入方式打开文件

ffile.seekp(sizeof(information)*p);

ffile.write((char *) &information,sizeof information);

ffile.close();

l++;

return;

}

}

p++;

}

efile.close();

if(l!=1)

cout<<"没有你所要修改的学生信息!"<<endl;

}

void omit()//这个函数起删除作用

{

int ch;

cout<<"请输入要删除的学生的学号:"<<endl;

cin>>ch;

ifstream out("student.txt",ios::nocreate);

ofstream in("student1.txt",ios::trunc);

while(out)

{ if(out.read((char*)&information,sizeof information))

if(ch!=information.getsno())

{ 

in.write((char*)&information,sizeof information); 

} 

}

in.close();

out.close();

ofstream gfile("student.txt",ios::trunc);//打开文件,如文件存在,删除其中全部数据;如文件不存在,建立文件

gfile.close();

ifstream ifile("student1.txt",ios::nocreate);

ofstream hfile("student.txt",ios::trunc);

while(ifile)

{ 

if(ifile.read((char*)&information,sizeof information))

hfile.write((char *)&information,sizeof information);

}

ifile.close();

hfile.close();

}

void output()

{

int i=0;

ifstream cfile("student.txt",ios::nocreate);

while(cfile)

{

if(cfile.read((char *)&information,sizeof information))//sizeof(information)的值是类中的一个元素的字节数。调用一次read函数,就将从information开始的类中的一个元素输入到磁盘文件中。

{ 

information.display();

i++;

}

}

if(i!=0)

cout<<"一共有"<<i<<"个学生信息"<<endl;

else 

cout<<"还没有输入学生信息"<<endl;

 

}

 

 

void select()

{

int ch;

do{

cin>>ch;

switch(ch)

{

case 0:

exit(0);

menu();

break;

case 1:

input();

menu();

break;

case 2:

information.search();

menu();

break;

case 3:

change();

menu();

break;

case 4:

omit();

menu();

break;

case 5:

output();

menu();

break;

 

default : 

menu(); 

cout<<"输入无效请重新输入(0======== 5)"<<endl; 

break;

}

}while(1);

}

 void main()

{ 

menu();

select();

}

 

 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?