C++读取多行输入

使用cin进行多行输入,每行进行求和

输入
1 2 3
4 5
0 0 0 0 0

输出
6
9
0
#include <iostream>
using namespace std;

int main()
{
    int input, res = 0;
    while(cin >> input){
        res += input;
        if(cin.get() == '\n'){
            cout << res << endl;
            res = 0;
        }
    }
    return 0;
}
posted @ 2020-08-11 18:34  libbin  阅读(1661)  评论(0编辑  收藏  举报