//导入文件到链表
int Creatlist(Linklist& L,const char* filename){
fstream file;
Linklist p, q;
p = L;
file.open(filename);
if (!file) {
cout << "出现错误"<<"\n";
return 0; }
file >> head_1 >> head_2 >> head_3;
while (!file.eof()) {
q = new LNode;
file >> q->data.id >> q->data.name >> q->data.score;
p->next = q;
p = q;
}
p->next = NULL;
file.close();
cout << "数据导入成功"<<"\n";
return 0;
}
void Viewlist(Linklist L) {
cout << head_1 << "\t\t" << head_2 << "\t\t" << head_3 << "\n";
Linklist p;
p = L;
p = p->next;
while (p) {
cout << p->data.id<<"\t\t"<< p->data.name<<"\t\t"<< p->data.score<<"\n";
p = p->next;
}
cout << "全部打印完毕"<<"\n";
}
/*部分运行结果如下:
1033 黄先宏 79
1034 贾成东 92
1035 姜爽 70
-842150451 -842150451
全部打印完毕
运行结果没问题,就是结尾有两个乱码,这是导入和打印的函数,求解决方式*/