what does this small line of code mean?

I don't think you can make a string stream == to something, so I'm wondering what function, this line of code was supposed to have?
 
ss = (std::stringstream{} << object << ss.str());
It uses the << operator to write object and then ss.str() into the stream.

Note that ss.str() gives a copy of the current content of the stream's internal buffer as string.

Since the << operator returns a reference to the stream on which it has been applied, you can "chain" these operators and/or assign the final result to a variable.

See here for details:
https://www.cplusplus.com/reference/ostream/ostream/operator%3C%3C/


The "long" from of the very same code would be:
1
2
3
4
std::stringstream temp;
temp << object;
temp << ss.str();
ss = temp;
Last edited on
The "long" from of the very same code would be:
1
2
3
4
5
std::stringstream temp;
temp << object;
temp << ss.str();
ss = std::move(temp); // move assign temp to ss 
// https://en.cppreference.com/w/cpp/io/basic_stringstream/operator%3D 
Topic archived. No new replies allowed.