第一次发帖,也不知道怎样才能被高人看见,不废话了,进入正题:
贴主在写一个学生信息管理系统的数据结构课程设计,新建学生信息需要两条路径,1是从键盘输入然后保存在txt文件中,2是从文件导入到函数中。现在已经实现了1,可是保存以后再以2方式读取就不匹配。现在想请各位大神指导一下如何实现学生信息:姓名学号科目成绩从文件中导入到函数。并且需要姓名学号科目成绩一一对应。
以下是我从键盘输入然后保存到txt的代码,小白,有错误多余欢迎指出,悉心求教,万谢!
void StuInHand(Student *head) //手动输入函数,由输入函数调用
{
ofstream stu("e:/file.txt", ios::out | ios::app );
if(head->next==NULL)
{
Student *point=(Student *)malloc(sizeof(Student));
point->next=NULL;
int s=1;
while(s==1)
{
Student *p=(Student *)malloc(sizeof(Student));
p->next=NULL;
StuIm(head,p);
if(head->next==NULL)
{
head->next=p;
point=p;
stu<name<num<subject<score;
}
else
{
point->next=p;
point=p;
stu<name<num<subject<score;
}
cout<<"是否继续: 1 是,2 否 ";
cin>>s;
}
stu.close();
}
else
{
cout<<"系统已存在信息,请转插入系统";
}
}