Như tiêu đề ạ, Mình làm bài tập đưa dữ liệu từ file lên rồi đưa vào trong Linked List. Nhưng khi xuất ra console thì không thấy đâu hết! Xin giúp đỡ!
/*
//Khai bao thu vien va tien xu ly
*/
#include <iostream>
using namespace std;
#include <string>
#include <fstream>
//Khai bao struct
struct Video
{
string sTenPhim = "", sTheLoai = "", sTenDaoDien = "", sTenDVNam = "", sTenDVNu = "", sHangSX = "";
int nNamSX = 0;
};
//khai vao struct tao doi tuong Node chua thong tinh sinh vien
struct Node
{
Video xData;
Node *pNext;
};
//Khai bao list chua 2 con tro tro vao node dau va cuoi
struct List
{
Node *pHead, *pTail;
List()
{
pHead = pTail = NULL;
}
};
//Khai bao nguyen mau ham
Node *createNode(Video xV);
void addHead(List &L, Video xV);
void doc_1_Video(ifstream &fileIn, Video &xV);
void xuat_1_video(Video xV);
void inputList(List &L, ifstream &fileIn);
void outputList(List L);
//chuong trinh chinh
void main()
{
List L;
Video xV;
ifstream fileIn;
fileIn.open("Video_Lesson14.txt", ios::in); //doc file len
inputList(L, fileIn); //doc danh sach sinh vien
outputList(L); //xuat danh sach sinh vien
fileIn.close(); //dong file
system("pause");
}
//xuat danh sach sinh vien ra ngoai man hinh
void outputList(List L)
{
Node *p = L.pHead;
for (p = L.pHead; p!= NULL; p = p->pNext)
{
xuat_1_video(p->xData);
}
}
//them du lieu vao linked list
void inputList(List &L, ifstream &fileIn)
{
Video xV;
while (!fileIn.eof() == true) //eof: end of file, neu dung con tro se tro den cuoi file
{
doc_1_Video(fileIn, xV); //doc danh sach mot sinh vien
addHead(L, xV); //them Node video vao dau danh sach
}
}
//xuat thong tin 1 video
void xuat_1_video(Video xV)
{
cout << "Ten phim: " << xV.sTenPhim << endl;
cout << "The Loai: " << xV.sTheLoai << endl;
cout << "Dao dien: " << xV.sTenDaoDien << endl;
cout << "Dien vien nam: " << xV.sTenDVNam << endl;
cout << "Dien vien nu: " << xV.sTenDVNu << endl;
cout << "Nam san xuat " << xV.nNamSX << endl;
cout << "Hang san xuat:" << xV.sHangSX << endl;
}
//doc du lieu tu file
void doc_1_Video(ifstream &fileIn, Video &xV)
{
getline(fileIn, xV.sTenPhim, ',');
rewind(stdin);
getline(fileIn, xV.sTheLoai, ',');
rewind(stdin);
getline(fileIn, xV.sTenDaoDien, ',');
rewind(stdin);
getline(fileIn, xV.sTenDVNam, ',');
rewind(stdin);
getline(fileIn, xV.sTenDVNu, ',');
fileIn >> xV.nNamSX;
fileIn.ignore(1);
rewind(stdin);
getline(fileIn, xV.sHangSX);
}
//them dau danh sach
void addHead(List &L, Video xV)
{
Node *pNew = createNode(xV);
if (L.pHead == NULL)
{
L.pHead = L.pTail = pNew;
}
else
{
pNew->pNext = L.pHead;
L.pHead = pNew;
}
}
//tao mot node moi
Node *createNode(Video xV)
{
Node *p = new Node;
if (p == NULL)
exit(1);
else
{
p->xData = xV;
p = NULL;
return p;
}
}
file txt:
the home 1,gia dinh,dao dien 1,nam 1,nu 1,1999,sony
iron man 1,hanh dong,dao dien 2,nam 2,nu 2,2008,marvel studio
end game,hanh dong,marvel comic,nam 3,nu 3,2011,marvel studio 2