Home > Back-end >  Bosses, I where there is a problem of this program
Bosses, I where there is a problem of this program

Time:10-24

, this is the procedure is to read the student information from a TXT file saved to the list, then enter student id, name and output performance, TXT files have a lot of lines, each line format is: student id name, this program does not have an error, but there is no response, is the black screen,
# include
# include
# include
# include
# include
# include
using namespace std;
Struct student {
Long id;
String name;
Int score;
Student * next;
Student * head;
};
Student * generatelist (const char * filename)
{
Ifstream file (" Score. TXT ");
Int independence idx=0;
The string line, part;
Student * head;
Student * p;
The head=(struct student *) malloc (sizeof (struct student));
The head - & gt; Next=NULL;
P=the head - & gt; Next=(struct student *) malloc (sizeof (struct student));
While (getline (file, line))
{
Stringstream ss (line);
Getline (ss, part, ' ');
While (idx
=2){
If (independence idx==0)
P - & gt; Id=stol (part);
Else if (independence idx==1)
P - & gt; Name=part;
Else if (independence idx==2)
P - & gt; Score=stoi (part);
Idx++;
}
P - & gt; Next=(struct student *) malloc (sizeof (struct student));
P=p - & gt; Next;
}
P - & gt; Next=NULL;
return head;
}
Void returnname (student * stulist, long id)
{
Student * p=stulist;
While (p - & gt; Id!=id & amp; & p!=NULL)
{
P=p - & gt; Next;
}
If (p!=NULL)
cout

The else
cout<" Could not find "& lt; }
Void returnscore (student * stulist, long id)
{
Student * p=stulist;
While (p - & gt; Id!=id & amp; & p!=NULL)
{
P=p - & gt; Next;
}
If (p!=NULL)
cout

}
Int main ()
{
Student * stulist=generatelist (" Score. TXT ");
Long xuehao;
cout<" Please enter a student id: ";
cin> Xuehao;
Returnname (stulist xuehao);
Returnscore (stulist xuehao);
}