为什么我这个数据存不进去也读不出来
#include<iostream>
#include<fstream>
using namespace std;
class Teacher{
char no[1024];
char name[100];
char gender[50];
int age;
char zc[50];
char xibu[50];
char zhuanye[50];
public:
friend void tj1(Teacher t[]);
friend void xs();
};
class XingZheng{
char no[1024];
char name[100];
char gender[50];
int age;
char zc[50];
char zm[50];
};
class TX:virtual public Teacher,virtual public XingZheng{
};
void tj1(Teacher t[]){
char m;
int i=0;
ofstream out("teacher.txt",ios::out | ios::binary);
while(1){
cout<<"Y输入,N退出"<<endl;
cin>>m;
if(m=='N'){
break;
}
else{
cout<<"编号:"<<endl;
cin>>t[i].no;
cout<<"姓名:"<<endl;
cin>>t[i].name;
cout<<"性别:"<<endl;
cin>>t[i].gender;
cout<<"年龄:"<<endl;
cin>>t[i].age;
cout<<"职称:"<<endl;
cin>>t[i].zc;
cout<<"系部:"<<endl;
cin>>t[i].xibu;
cout<<"专业:"<<endl;
cin>>t[i].zhuanye;
out.write((char*)&t[i],sizeof(t));
out.close();
i++;
}
}
}
void xs(){
Teacher t;
ifstream in("teacher.txt",ios::in|ios::binary);
if(!in){
cout<<"打开失败"<<endl;
}
while(in.read((char*)&t,sizeof(t))){
cout<<t.no<<" "<<t.name<<" "<<t.gender<<" "<<t.age<<" "<<t.zc<<" "<<t.xibu<<" "<<t.zhuanye<<endl;
}
in.close();
}
int main(){
Teacher t[100];
tj1(t);
xs();
}
你tj1的函数else 需要 输一次++一次