devxlogo

Read and Write Strings Using String Streams

Read and Write Strings Using String Streams

String streams allow reading and writing strings just like cin and cout allow reading standard input and writing standard output. String streams may be used by including .

Reading from a string is similar to reading input using cin:

string s = "word 5";istringstream iss(s);string w;int n;iss >> w >> n;

Writing to a string is similar to writing output using cout:

ostringstream oss;oss << "This is a number: " << 5;string s = oss.str();
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist