im trying to write a program that reads from a text file into a linked list
here is the list structure.
#include <iostream> #include <string> #include <fstream> using namespace std; struct Video { char video_name[1024]; // video name int ranking; // Number of viewer hits char url[1024]; // URL Video *next; // pointer to Video structure } *head = NULL; // EMPTY linked list
here is the code to read:
void load() { struct Video *temp; temp = (Video*)malloc(sizeof(Video)); //allocate space for node temp = head; ifstream rankFile ("Ranking.dbm"); if (rankFile.is_open()) { while ( rankFile.good() ) { cin.getline(rankFile, temp->video_name, "\n"); cin.getline(rankFile, temp->ranking, "\n"); cin.getline(rankFile, temp->url, "\n"); temp = temp->next; } myfile.close(); } else cout << "Unable to open file"; return ; }
it is read from the text file Ranking.dbm , which looks like this:
bagheera 20 bagheera.com sushi 60 sushi.com wicket 99 wicket.com teek 100 teek.com
however, I get an error: Invalid conversion from void* to char* in all 3 of my cin.getline() statements while reading from a file. I need to be able to read line by line from my file ( Ranking.dbm ) and store each set of 3 lines until temp->video_name , temp->ranking and temp->url , and then create new nodes and save the next 3 lines. .. so on and so forth until ive reads everything from the file.
How can i do this? Am I talking about this completely wrong or is it just a syntax error? I am still getting C ++ freeze: /
source share