![](/img/trans.png)
[英]Error:C2679 binary '==': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion
[英]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;
}
}
My 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:二進制'<<':未找到采用'std :: string'類型的右側操作數的運算符(或沒有可接受的轉換)
您可能忘記了:
#include <string>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.