Student* readfile(Student *head)
{
ifstream infile("student.txt", ios::in);
if (!infile)
{
cout << "通訊錄打開失敗" << endl;
exit(1);
}
Student *head1, *head2;
head = new Student;
head1 = head;
while (!infile.eof())
{
infile >> head1->Name;
infile >> head1->Stunum;
head2 = head1;
head1 = new Student;
head2->next = head1;
}
head1->next = NULL;
Student *head3 = head;
while (head3 != NULL)
{
cout << head3->Name << endl;
cout << head3->Stunum << endl;
head3 = head3->next;
}
return head;
}
我想把student.txt里的資料讀入這個鏈表,為什么一直顯示出錯呢?
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/111486.html
標籤:基礎類
上一篇:TR069 cpe的開發
