struct nodetype
{
string info;
nodetype* link;
};
vector<string> THIRDSTEP::FindMovies(string cloc)
{
int i = 0;
string chose;
nodetype *movies;
nodetype *h = NULL;
nodetype *c = NULL;
ifstream infile;
infile.open("C:\\Users\\User\\Desktop\\MP 116\\mov.txt");
while (i < 10)
{
getline(infile, chose, ',');
movies = new nodetype;
movies->info = chose;
movies->link = NULL;
if (h == NULL)
{
h = movies;
c = movies;
i++;
}
else
{
c->link = movies;
c = movies;
i++;
}
}
// displaying the list of movies
nodetype *temp;
vector<string> mov(10);
int j = 0;
temp = h;
while (temp != NULL)
{
mov[j] = temp->info;
temp = temp->link;
j++;
}
return mov;
infile.close();
}
这是我对此功能的完整代码。它可以正常工作,直到它显示电影列表。调试后,temp->info
不会进入mov[j]
,因此不会产生任何输出。我认为我所做的是正确的我只是不明白为什么mov[j]
没有阅读temp->info
。