bir hata alıyorum:Neden std :: string yazımı bilinmeyen bir işleç << neden hata yapıyor? Benim yöntemlerinden birini çıkışa dönüş değeri çalıştığınızda
Error: No operator "<<" matches these operands. Operand types are: std::ostream << std::string
main.cpp
#include <iostream>
using namespace std;
#include "Book.h"
int main()
{
book.setTitle("Advanced C++ Programming");
book.setAuthorName("Linda", "Smith");
book.setPublisher("Microsoft Press", "One Microsoft Way", "Redmond");
book.setPrice(49.99);
cout << book.getBookInfo(); // <-= this won't compile because of the error above.
int i;
cin >> i;
return 0;
};
Yöntem dönmelidir dizesi:
string Book::getBookInfo()
{
stringstream ss;
ss << title << endl << convertDoubleToString(price) << endl;
return ss.str();
}
'<< işleci '' yi aşırı yüklemeniz gerekir. – Rapptz
@Rapptz - hayır, burada değil; "GetBookInfo" üye işlevi bir dize döndürür ve bu dize eklenir. –
str :: string' nedir? –