Demonstrate string streams : stringstream « File Stream « C++ Tutorial






#include <iostream> 
#include <sstream> 
using namespace std; 
 
int main() 
{ 
  stringstream s("This is initial string."); 
 
  // get string 
  string str = s.str(); 
  cout << str << endl; 
 
  // output to string stream  
  s << "Numbers: " << 10 << " " << 123.2; 
 
  int i; 
  double d; 
  s >> str >> i >> d; 
  cout << str << " " << i << " " << d; 
 
  return 0; 
}
This is initial string.
Numbers: 10 123.2








12.20.stringstream
12.20.1.Demonstrate string streams
12.20.2.Use stringstream to parse a number
12.20.3.stringstream::str( empty string): Empty the string
12.20.4.stringstream::str( ) returns a string