C++ › I/O Streams

What is std::stringstream and when is it useful?

Intermediate

Answer

std::stringstream (and ostringstream/istringstream) is an in-memory stream backed by a std::string. It's used to build formatted strings, parse strings into typed values, and convert between text and numbers using the familiar << / >> operators—handy for tokenizing input or assembling output without file/console I/O.
std::ostringstream oss;
oss << "x=" << 5;
std::string s = oss.str();   // "x=5"
Real-world example A logger assembles a formatted message in an ostringstream before writing it out in one call.

Common follow-ups: How do you get the resulting string? | How can it parse input?