Skip to main content

Command Palette

Search for a command to run...

Effortlessly play with stringstream

Published
1 min read
Effortlessly play  with stringstream
R

I am a C++ developer with expertise in building solutions for onboard embedded devices and products, has a penchant for building REST API backends with Spring boot and Node JS express framework

Skill Cloud: MQTT, IoT, SSL, HTTP, TLS, REST API, curl, Node JS, Express, Java, Spring Boot, MongoDB

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; 

}