Hi, how do you read multiple data types in a file and storing it in a linked list. I read the items with no linked list but when I used linked list it doesnt work. I think there is something wrong in my code. Programming language: C++ Thank you
struct Video {
int videoID;
string movieTitle;
string movieGenre;
string movieProduction;
int numberOfCopies;
};
class videoList {
private:
struct videoNode {
Video video;
struct videoNode *next;
};
videoNode *head;
public:
videoList(); //constructor
//~videoList(); //deconstructor
void insertNewVideo (Video vid);
void rentVideo (Video vid);
void returnVideo (Video vid);
void showVideoDetails (Video vid);
void displayVideo ();
bool isVideoExist();
void exit ();
void generateVideoID();
void readVideoFile();
};
void videoList::readVideoFile () {
videoNode *nodePtr;
ifstream file( "videoList.txt" ) ;
string line ;
string id, movieTitle, movieGenre, movieProduction, numberOfCopies;
if (!file) {
cout << endl << "\t\t\t\t There is file!" << endl;
}
else {
std::stringstream linestream(line);
cout << endl << "\t\t\t\t Movie List " << endl;
nodePtr = head;
while (nodePtr)
while (getline(file, line)){
{
std::getline(linestream, id, ',');
std::getline(linestream, nodePtr->video.movieTitle, ',');
std::getline(linestream, nodePtr->video.movieGenre, ',');
std::getline(linestream, nodePtr->video.movieProduction, ',');
linestream >> nodePtr->video.numberOfCopies;
if(linestream) // true if there were no errors reading the stream
{
std::cout << id << '\n';
std::cout << nodePtr->video.movieTitle << '\n';
std::cout << nodePtr->video.movieGenre << '\n';
std::cout << nodePtr->video.movieProduction << '\n';
std::cout << nodePtr->video.movieTitle << '\n';
}
}
}
}
}