AlgoMaster Logo

String Streams (stringstream, istringstream, ostringstream)

Medium Priority15 min readUpdated June 6, 2026

String streams treat an in-memory std::string like a file: write to it with <<, read from it with >>, and use the rest of the C++ stream API. They live in the <sstream> header and come in three flavours: std::ostringstream for building strings, std::istringstream for parsing strings, and std::stringstream for both directions. This chapter covers how each one works, when one fits better than the other, and the small set of pitfalls associated with them.

Premium Content

Subscribe to unlock full access to this content and more premium articles.