主题:为什么向TXT传送数据不正确的显示呢?
为什么我输入新建信息以后,打开TXT文本查看,
里面的信息除了几个汉字以外什么都没有呢?
求教
#include <iostream.h>
#include <fstream.h>
#include <string.h>
//基类
class person
{
public:
person();
char name[20];
char sex;
int age;
};
person::person(){}
//学生类
class student: public person
{
public:
student();
void xinjian();
void xiugai();
void shanchu();
char ID[10];
char pro[20];
int rank;
};
//老师类
class teacher: public person
{
public:
teacher();
void xinjian1();
void xiugai1();
void shanchu1();
char num[10];
char com[20];
char subject[20];
};
teacher::teacher(){};
teacher tea[100];
student stu[100];
ofstream outfile("f1.txt",ios::app|ios::nocreate);
student::student(){}
//新建学生信息
void student::xinjian()
{
int i=0,a;
do
{
cout<<"请输入新建学生信息:"<<endl;
cout<<"输入姓名:";
cin>>stu[i].name;
cout<<"输入性别:";
cin>>stu[i].sex;
cout<<"输入年龄:";
cin>>stu[i].age;
cout<<"输入学号:";
cin>>stu[i].ID;
cout<<"输入专业:";
cin>>stu[i].pro;
cout<<"输入排名:";
cin>>stu[i].rank;
i++;
outfile<<"姓名"<<stu[i].name<<" "<<"性别"<<stu[i].sex<<" "<<"年龄"<<stu[i].age<<" ";
outfile<<"学号"<<stu[i].ID<<" "<<"专业"<<stu[i].pro<<" "<<"排名"<<stu[i].rank<<endl;
cout<<"数据录入成功,是否继续录入,选择是请按1,否请按0:";
cin>>a;
}while(a==1);
}
//新建老师信息
void teacher::xinjian1()
{
int i=0,a;
do
{
cout<<"请输入新建老师信息:"<<endl;
cout<<"输入姓名:";
cin>>tea[i].name;
cout<<"输入性别:";
cin>>tea[i].sex;
cout<<"输入年龄:";
cin>>tea[i].age;
cout<<"输入工号:";
cin>>tea[i].num;
cout<<"输入单位名称:";
cin>>tea[i].com;
cout<<"输入教授课程:";
cin>>tea[i].subject;
i++;
outfile<<"姓名"<<tea[i].name<<" "<<"性别"<<tea[i].sex<<" "<<"年龄"<<tea[i].age<<" ";
outfile<<"工号"<<tea[i].num<<" "<<"单位名称"<<tea[i].com<<" "<<"教授课程"<<tea[i].subject<<endl;
cout<<"数据录入成功,是否继续录入,选择是请按1,否请按0:";
cin>>a;
}while(a==1);
}
//修改学生信息
void student::xiugai()
{
char num[20];
int i=0,a;
bool enter=0;
do
{
cout<<"请输入您要修改的学生的学号:";
cin>>num;
do
{
if(strcmp(num,stu[i].ID)==0)
{
enter=1;
break;
}
else i++;
}while(enter==0,i<100);
if(enter==1)
{
cout<<"请出入改正后的学生信息:"<<endl;
cout<<"输入姓名:";
cin>>stu[i].name;
cout<<"输入性别:";
cin>>stu[i].sex;
cout<<"输入年龄:";
cin>>stu[i].age;
cout<<"输入学号:";
cin>>stu[i].ID;
cout<<"输入专业:";
cin>>stu[i].pro;
cout<<"输入排名:";
cin>>stu[i].rank;
cout<<"数据修改成功";
}
if(enter==0)
cout<<"你输入的学号有误,请检查后重新输入:"<<endl;
cout<<"是否继续修改,是请按1,否请按0:";
cin>>a;
}while(a==1);
}
//修改老师信息
void teacher::xiugai1()
{
char number[20];
int i=0,a;
bool enter=0;
do
{
cout<<"请输入您要修改的老师的工号:";
cin>>num;
do
{
if(strcmp(number,tea[i].num)==0)
{
enter=1;
break;
}
else i++;
}while(enter==0,i<100);
if(enter==1)
{
cout<<"请出入改正后的老师信息:"<<endl;
cout<<"输入姓名:";
cin>>tea[i].name;
cout<<"输入性别:";
cin>>tea[i].sex;
cout<<"输入年龄:";
cin>>tea[i].age;
cout<<"输入工号:";
cin>>tea[i].num;
cout<<"输入单位名称:";
cin>>tea[i].com;
cout<<"输入教授课程:";
cin>>tea[i].subject;
cout<<"数据修改成功";
}
if(enter==0)
cout<<"你输入的工号有误,请检查后重新输入:"<<endl;
cout<<"是否继续修改,是请按1,否请按0:";
cin>>a;
}while(a==1);
}