error C2679: 二进制“<<”: 没有找到接受 'std::string' 类型右手操作数的运算符
error C2679: binary '<<':no operator found which takes a right-hand operand of type 'std::string'
我有一个简单的图书链表,我正在尝试使用这种方法打印链表的内容
void List::display()const{
Node *newNode = head;
while (newNode != NULL){
cout << "ID: " << newNode->book.getId() << " Name: " << newNode->book.getName()<< endl;
newNode = newNode->next;
}
}
我的Book
class有以下实现:
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;
我之前在几个不同的链表中尝试过这个并且它工作正常,但我无法弄清楚这里有什么问题,
错误是:
Error 1 error C2679: binary '<<' : no operator found which takes a
right-hand operand of type 'std::string' (or there is no acceptable
conversion)
你可能忘记了:
#include <string>
我有一个简单的图书链表,我正在尝试使用这种方法打印链表的内容
void List::display()const{
Node *newNode = head;
while (newNode != NULL){
cout << "ID: " << newNode->book.getId() << " Name: " << newNode->book.getName()<< endl;
newNode = newNode->next;
}
}
我的Book
class有以下实现:
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;
我之前在几个不同的链表中尝试过这个并且它工作正常,但我无法弄清楚这里有什么问题,
错误是:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
你可能忘记了:
#include <string>