运行此代码时,我得到一个奇怪的结果
void MovieDatabase:: showMovie(const string mtitle){
cout << "The informations about the" << mtitle << endl;
for(Movie* cur = headMovie; cur ->next !=NULL; cur= cur->next){
if(cur -> title == mtitle){
cout <<"Movie title is "<< cur ->title << endl;
//cout < "The name of director is " << cur -> firstNameOfDirector << endl;
cout << "The last name of director is " << cur -> lastNameOfDirector <<endl;
cout << "The year that the movie is released " << cur -> year << endl;
cout << "The day that the movie is released " << cur -> day << endl;
cout << "The month that the movie is released " << cur -> month << endl;
}
}
cout << endl;
}
这是我正在检查影片标题的代码,如果它们在链接列表中,则我正在打印有关电影的详细信息。但是,作为输出,它仅打印以下行
cout << "The informations about the" << mtitle << endl;`
我不明白有人可以提供帮助的原因是什么?
最佳答案
检查以确保您的字符串确实相等,并且其中之一没有隐藏的\r
或\n
或尾随空格。
另外,如注释中所述,您可能希望循环终止条件为cur != NULL
而不是cur->next != NULL
。
关于c++ - 测试链接列表中的指针,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13975115/