テキストファイルからリンクリストに読み込むプログラムを書き込もうとしています
これがリスト構造です。
#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
読み取りコードは次のとおりです。
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 ;
}
Ranking.dbm
次のようなテキストファイルから読み取っています。
bagheera
20
bagheera.com
sushi
60
sushi.com
wicket
99
wicket.com
teek
100
teek.com
ただし、ファイルからの読み取り中に3つのステートメントInvalid conversion from void* to char*
すべてでエラーが発生します。cin.getline()
ファイル ( Ranking.dbm
) から 1 行ずつ読み取り、3 行の各セットを に保存しtemp->video_name
、新しいノードを作成して次の 3 行を保存temp->ranking
できるようにする必要があります。temp->url
ファイルからすべて。
これどうやってするの?私はこれを完全に間違った方法で行っていますか、それとも単なる構文エラーですか? 私はまだC++のコツをつかんでいます:/