VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stringstream-c-applications/

⇱ stringstream in C++ and its Applications - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

stringstream in C++ and its Applications

Last Updated : 26 Aug, 2025

A stringstream is a part of the C++ Standard Library, defined in the <sstream> header file. It allows us to read from and write to strings like they are streams.

It lets us take a string and extract data from it (like from cin), It also lets us build strings by inserting data into it (like into cout).

Types of String Streams

There are three types of string stream classes in C++:

Class

Purpose

stringstream

Both input and output

istringstream

Input only (like cin)

ostringstream

Output only (like cout)

Uses or Applications of stringstream:

Convert String to Integer


Output
Integer: 123

Convert Integer to String


Output
String: 456

Split a Sentence into Words


Output
C++
is
powerful

Combine multiple values into a String


Output
Name: John, Age: 25

Resetting or Clearing a stringstream


Output
Before clearing: Hello, world!
After clearing and reuse: New data here!
Comment
Article Tags: