C++ ostringstream`.str()没有匹配的函数调用`

C++ ostringstream`.str()没有匹配的函数调用`,c++,ostringstream,C++,Ostringstream,我有一个函数,定义为 void writeSite(string& site, const string& contentType); 现在,我正在使用std::ostringstream函数构建字符串 完成字符串后,我想调用writeSite函数。但我得到了以下错误: no matching function for call to ‘writeSite(std::basic_ostringstream<char>::__string_type, const ch

我有一个函数,定义为

void writeSite(string& site, const string& contentType);
现在,我正在使用
std::ostringstream
函数构建字符串

完成字符串后,我想调用
writeSite
函数。但我得到了以下错误:

no matching function for call to ‘writeSite(std::basic_ostringstream<char>::__string_type, const char [17])’
   writeSite(body.str(), "application/json");
当你这样做的时候

writeSite(body.str(), "application/json");
body.str()
返回的字符串对象是临时的。非常量引用不能绑定到临时对象


一个简单的解决方案是使
site
参数
const
与您对
contentType
参数所做的一样(否则会遇到相同的问题)。

对不起,这是一个主要的示例,说明了为什么需要使用。我敢肯定你自己也会发现这个小错误。你能把函数的签名改为
void writeSite(const string&site,const string&contentType)
writeSite(body.str(), "application/json");