Demonstrating input from an istringstream object : istrstream « File Stream « C++ Tutorial






#include <iostream>
using std::cout;
using std::endl;

#include <string>
using std::string;

#include <sstream>
using std::istringstream;

int main()
{
   string input( "Input test 123 4.7 A" );
   istringstream inputString( input );

   string string1;
   string string2;

   int integer;
   double double1;
   char character;

   inputString >> string1 >> string2 >> integer >> double1 >> character;

   cout << "\nstring1: " << string1
      << "\nstring2: " << string2 << "\n   int: " << integer
      << "\ndouble: " << double1 << "\n  char: " << character;

   return 0;
}
string1: Input
string2: test
   int: 123
double: 4.7
  char: A"








12.17.istrstream
12.17.1.Attempt to read from empty stream
12.17.2.Demonstrating input from an istringstream object
12.17.3.Use istrstream to read int, float and char
12.17.4.How to read the contents of any array that contains text
12.17.5.Read and display binary data