这是将记录写入文件的功能。
void getfadata()
{
cout<<"\nEnter the Faculty Name : ";
gets(name);
cout<<"\nEnter the Faculty ID/Roll no. : ";
cin>>rollno;
cout<<"\nEnter the Faculty Father's Name : ";
gets(fname);
cout<<"\nEnter the Mobile No. : ";
gets(mobile);
cout<<"\nEnter the E-Mail ID : ";
gets(mail);
cout<<"\nEnter the Total Subjects : ";
cin>>totsub;
//cout<<"\nThe total subjects chosen are : "<<totsub;
for(int i=0;i<totsub;i++)
{
cout<<"\nEnter the Subject "<<i+1<<" Name : ";
cin>>subject[i];
}
pass:
cout<<"\nCreate Your Login Password "
"(Password should be of 10 characters.) : ";
int k;
for(k=0;k<10;k++)
{
passwd[k]=getch();
cout<<"*";
}
getch();
cout<<"\nRe-Enter the above password : ";
for(k=0;k<10;k++)
{
repasswd[k]=getch();
cout<<"*";
}
getch();
if(strcmp(passwd,repasswd)==0)
{
cout<<"\nEnter the Unique Keyword to Recover Password : ";
cin>>rpasswd;
cout<<"\n\nPlease note your UserName and ID/Roll no. \n";
}
else
{
cout<<"\nPassword do not match."<<endl;
char t;
cout<<"\nDo you want to try again (y/n) : ";
cin>>t;
while(t=='y'||t=='Y')
goto pass;
}
}
此功能显示记录。
if(tmp==3)
{
ifstream fs;
fs.open("fainfo.txt",ios::in);
fs.seekg(0);
while(!fs.eof())
{
fs.read((char *)&a,sizeof(Admin));
a.fadisplay();
}
fs.close();
}
我希望输出为:
院系名称:Bhavesh
学院编号/卷号:101
教父的名字:Abhay
教师手机号:123456789
教师电子邮件ID:abcd34@gmail.com
学院学科:2
主题1:数学
主题2:科学
但是实际输出是:
院系名称:Bhavesh
学院编号/卷号:101
教父的名字:Abhay
教师手机号:123456789
教师电子邮件ID:abcd34@gmail.com
学院学科:2
主题1:数学
主题2:科学
院系名称:Bhavesh
学院编号/卷号:101
教父的名字:Abhay
教师手机号:123456789
教师电子邮件ID:abcd34@gmail.com
学院学科:2
主题1:数学
主题2:科学