CPP 14
Stringstream1.cpp Guest on 2nd October 2020 11:12:52 AM
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. using std::cout;
  5. using std::endl;
  6. using std::istringstream;
  7. using std::ostringstream;
  8. using std::string;
  9.  
  10. int main() {
  11.     ostringstream os;
  12.     string s("hello");
  13.     int i = 10;
  14.     double d = 11.5;
  15.     char c = 'a';
  16.  
  17.     os << s << ", " << i << ", " << d << ", " << c;
  18.     cout << os.str() << endl;
  19.  
  20.     istringstream is("20 world 19.4 x");
  21.     is >> i >> s >> d >> c;
  22.     cout << "i: " << i << endl;
  23.     cout << "s: " << s << endl;
  24.     cout << "d: " << d << endl;
  25.     cout << "c: " << c << endl;
  26. }
  27.  
  28. #if 0
  29. $ stringstream1
  30. hello, 10, 11.5, a
  31. i: 20
  32. s: world
  33. d: 19.4
  34. c: x
  35. #endif

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.