There are several issues. First, as Yushi points out, the type of the ss << "MB" expression is std::ostream& , not std::stringstream , and there is no implicit conversion from std::ostream to std::stringstream . Secondly, streams cannot be copied, so you can never return a std::stringstream (which will require a copy). And also you cannot just change the return value to std::ostream& , because this will return a reference to the local variable; ss will be destroyed at the end of the function.
What are you trying to achieve? Most of the time, just returning a string ( ss.str() ) would be a better solution.
source share