Skip to main content

Effortlessly play with stringstream

Published 1 min readMarkdown
Effortlessly play  with stringstream

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; 

}

About the author

  • 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

No comments yet. Be the first to comment.