A stringstream is a stream that works on strings. It helps to perform IO operations on strings stringstream is versatile for parsing text in C++
Commonly used operations on stringstreams are,
- Extract data from stream >>
- Enter data into stream <<
- str() Returns stream content as a string
Look into the below example for a demo,
#include <sstream>
#include <iostream>
using namespace std;
int main ()
{
stringstream ssm;
string token;
stringstream source("All or nothing");
cout << "source: " << source.str() << endl;
if (ssm >> token)
cout << "Extracted token: " << token << endl;
}