[英]Testing the pointers in a linked list
當我運行此代碼時,我有一個奇怪的結果
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;
}
這是我正在檢查movietitle的代碼,如果它們在鏈表中,我正在打印有關電影的詳細信息。 但是,作為輸出,它只是打印出那條線
cout << "The informations about the" << mtitle << endl;`
我無法理解任何人可以幫助的原因是什么?
檢查以確保您的字符串確實相等,並且其中一個字符串中沒有隱藏的\\r
或\\n
或\\n
或尾隨空格。
同樣如評論中所述,您可能希望循環終止條件為cur != NULL
而不是cur->next != NULL
。
有兩種可能性:
mtitle
。 next == NULL
),你的while
循環就會結束而不檢查它。 在不知道列表內容的情況下,我們無法知道這里的情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.