String Streams

The string stream family lets us store and manipulate strings.

We'll cover the following

Streams #

A stream is an infinite data stream on which we can push or pull data. String streams and file streams enable strings and files to interact with the stream directly.

String streams #

String streams need the header <sstream>. They are not connected to an input or output stream and store their data in a string.

Whether we use a string stream for input, or output or with the character type char or wchar_t there are various string stream classes:

Class Use
std::istringstream and std::wistringstream String stream for the input of data of type char and wchar_t.
std::ostringstream and std::wostringstream String stream for the output of data of type char and wchar_t.
std::stringstream and std::wstringstream String stream for the input or output of data of type char and wchar_t.

Typical operations on a string stream are to:

  • Write data to a string stream:

Get hands-on with 1000+ tech skills courses.