193030

SStream reading, reseting

Apr 2nd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. // Example program
  2. #include <iostream>
  3. #include <string>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.     int first, second;
  8.     string input;
  9.  
  10. int main()
  11. {
  12.   stringstream sstream;
  13.  
  14.     cout << "First integer: ";
  15.     getline(cin, input);
  16.     sstream.str(input);
  17.     sstream >> first;     // state of sstream may be eof
  18.    
  19.     cout << "Second integer: ";
  20.     getline(cin, input);
  21.     sstream.str(input);
  22.     sstream.clear();      // clear eof state
  23.     sstream >> second;    // input from sstream
  24. }
Add Comment
Please, Sign In to add comment