bool Addstu(STU *head)//传入头指针,头指针不为空
{
int numofaddstu;
STU *currentp;
currentp=head;
STU *newp;
while (currentp->next)
{
currentp = currentp->next;
}
cout<<"请输入添加学生人数:"<<endl;
cin>>numofaddstu;
for (int i = 0;i<numofaddstu;i++)
{
newp = new STU;
if (newp == NULL)
{
cout<<"内存分配失败!"<<endl;
exit(0);
}
cout<<"输入第"<<i+1<<"个学生信息"<<endl;
cin>>newp->name>>newp->id>>newp->mathscore>>newp->engscore>>newp->mathscore;
currentp->next = newp;
currentp=newp;
}
currentp->next = NULL;
if (Savedata(head))
{
cout<<"保存成功"<<endl;
return true;
}
else
return false;
}
程序运行到输入操作完成之后就崩溃掉了。输入以后的操作都无法执行。请问是哪里弄错了 |