193030

String stream

Mar 30th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 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.  
  16.    getline(cin, input);
  17.    stringstream  stream(input);
  18.  
  19. string  word;
  20.  
  21. stream >> word;  // word now holds 'I'
  22. int number = atoi(word.c_str());
  23. for(int i =0 ; i<number; i++)
  24. {
  25.     stream >> word;  // word now holds 'am'
  26.     cout << word << endl;
  27.  
  28. }
  29.  
  30.  
  31.  
  32. }
Add Comment
Please, Sign In to add comment