I am getting an error when I try to output the return value from one of my methods:
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;
};
Method which should return string:
string Book::getBookInfo()
{
stringstream ss;
ss << title << endl << convertDoubleToString(price) << endl;
return ss.str();
}
<< operator
. – LeeanngetBookInfo
returns a string, and that string gets inserted. – Piccardtitle
declared anywhere. – Fomentstr::string
- shouldn't that bestd::string
? – Worldlywisecout
in the method withoutcout
in main method it works just fine. I just wonder why this wont work the way I am presenting. :) – Dowland