I have a function which is defined as
void writeSite(string& site, const string& contentType);
Now I am building my string with the std::ostringstream
function.
After finishing the string I want to call the writeSite
function. But I get the following error:
no matching function for call to ‘writeSite(std::basic_ostringstream<char>::__string_type, const char [17])’
writeSite(body.str(), "application/json");
I can solve the problem if I first save the ostringstream
to a new std::string
variable and then call the writeSite
function.
But I was wondering, if there is a better option?
std::ostringstream body;
body << "{";
// some more string building
body << "}";
std::string sbody = body.str();
writeSite(sbody, "application/json");