193030

SStream, multiple number from lane

Apr 1st, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 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.  
  15.  
  16. int k =0;
  17. cin >> k;
  18. cin.ignore();
  19.  
  20. string input;
  21. string  word;
  22. int sum =0;
  23.  
  24. for(int i =0 ; i<k; i++)
  25. {
  26.     getline(cin, input);
  27.    // cin.ignore();
  28.     stringstream stream(input);
  29.     while(stream >> word!=0) {
  30.     int number = atoi(word.c_str());
  31.     sum += number;
  32.     }
  33. }
  34. cout << sum;
  35.  
  36.  
  37. }
Add Comment
Please, Sign In to add comment