我有一个简单的书籍链表,我试图用这种方法打印链表的内容
void List::display()const{
Node *newNode = head;
while (newNode != NULL){
cout << "ID: " << newNode->book.getId() << " Name: " << newNode->book.getName()<< endl;
newNode = newNode->next;
}
}
我的Book
类具有以下实现:
int Book::getId(){
return id;
}
string Book::getName(){
return name;
}
Book.h
具有以下声明:
class Book{
friend class Node;
friend ostream& operator<<(ostream& output, const Book &book);
public:
Book();
int getId();
string getName();
private:
int id;
string name;
};
让它打印本书的ID
很好:
cout << "ID: " << newNode->book.getId()
它的第二部分不起作用:
cout<<" Name: " << newNode->book.getName()<< endl;
我之前在几个不同的链接列表中试过这个并且它运行正常,但我无法弄清楚这里有什么问题,
错误是:
错误1错误C2679:二进制&#39;&lt;&lt;&#39; :找不到哪个运营商需要 类型&#39; std :: string&#39;的右侧操作数(或者没有可接受的 转化率)
答案 0 :(得分:2)
你可能忘了:
#include <string>