193030

String stream edited

Mar 31st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <sstream>      // std::stringstream
  5.  
  6. using namespace std;
  7.  
  8.  
  9.  
  10.  
  11.  
  12. int main() {
  13.     string inputString = "The code is getting better code.";
  14.    string input;
  15.   // getline(cin, input);
  16.  
  17.    stringstream  stream(inputString);
  18.  
  19. string  word;
  20.  
  21. stream >> word;  // word now holds 'The'
  22. cout << word << endl;
  23.  
  24. for(int i =0 ; i<5; i++)
  25. {
  26.     stream >> word;  // word now holds 'code'
  27.     cout << word << endl;
  28.  
  29. }
  30.  
  31.  
  32.  
  33. }
Add Comment
Please, Sign In to add comment