193030

Unlimited rows sum SStream

Apr 1st, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 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. int main() {
  9.  
  10. string input;
  11. string  word;
  12. int sum =0;
  13.  
  14.     while(getline(cin, input)){
  15.       stringstream stream(input);
  16.       while(stream >> word!=0) {
  17.       int number = atoi(word.c_str());
  18.       sum += number;
  19.      }
  20.      if (input.empty())
  21.        break;
  22.      cout << sum << endl;
  23.  
  24.     }
  25.  
  26.  
  27. }
Add Comment
Please, Sign In to add comment