Demonstrating ostringstream

Figure 19.11 demonstrates an ostringstream object. The program creates ostringstream object outputString (line 10) and uses the stream insertion operator to output a series of strings and numerical values to the object.

 1   // Fig. 19.11: Fig19_11.cpp 2   // Using an ostringstream object. 3   #include <iostream> 4   #include <string> 5   #include <sstream> // header for string stream processing      6   using namespace std; 7  8   int main() 9   {10      ostringstream outputString; // create ostringstream instance 11 12      string string1( "Output of several data types " );13      string string2( "to an ostringstream object:" );14      string string3( "\n        double: " );15      string ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.