if(!f)
{
exits();
}
f.write((char*)&"temp",sizeof(student));//writes an the end of file, dont over-write previous data.
f.close();
}
void group::addrec( )
{
char ch;
f.seekp(0L,ios::end);
do
{
cout<<"\n<<TO RETURN THE MAIN MENU PRESS 'R' ADD INFORMATION PRESS 'N' >>:";
cin>>ch;
if(ch=='r'||ch=='R')
main();
cout<<"\nPlease enter the followings:"<<"\n";
cout<<"\nStudent Id:";
cin>>p.Stdid;
cout<<"\nStudent Name:";
cin>>p.Stdname;
cout<<"\nClass :";
cin>>p.Class;
cout<<"\nPostion:";
cin>>p.Position;
f.write((char*)&p,sizeof(p));
cout<<"\nAAre you sure to add new member information?(Y/N):";
cin>>ch;
cout<<"\n";
}
while(ch=='y'||ch=='Y');
}
void group::listrec()
{
int j=1,a,c=0;
f.seekg(0L,ios::beg);
cout<<"\nPrint the member list as followings:";
cout<<"\n\n\n\n "<<"Student Id"<<" "<<" Student Name"<<" "<<"Class"<<" "<<"Postion"<<"";
cout<<"\n\t ---------------------------------------";
while(f.read((char*)&p,sizeof(p)))
{
cout<<"\n";
Actually, we never give full solutions around here.
What the heck are you doing? Of course nothing will print out because your stream is always closed when you do try to write. Similarly, nothing will be read for that same reason. You need to open your stream before you do any operations on it. You open your stream only once and that is in the constructor and that stream is later closed.