Demonstrating istringstream

Figure 19.12 demonstrates input from an istringstream object. Lines 10–11 create string input containing the data and istringstream object inputString constructed to contain the data in string input. The string input contains the data

Input test 123 4.7 A

which, when read as input to the program, consist of two strings ("Input" and "test"), an int (123), a double (4.7) and a char ('A'). These characters are extracted to variables string1, string2, integer, double1 and character in line 18.

 1   // Fig. 19.12: Fig19_12.cpp 2   // Demonstrating input from an istringstream object. 3   #include <iostream> 4   #include <string> 5   #include <sstream>       6   using namespace std; 7  

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.