#include<iostream>
using namespace std;
int main(){
int value,sum=0;
while(cin>>value){
sum+=value;
}
cout<<"The sum of the values is "<<sum;
return 0;
}
按非法字符或CTRL+Z+enter中止
本文介绍了一个使用C++编写的简单程序,该程序能够接收用户在控制台输入的一系列整数,并计算这些整数的总和。程序通过标准输入流读取数值,直到遇到非法输入或用户按下CTRL+Z+Enter组合键为止。
#include<iostream>
using namespace std;
int main(){
int value,sum=0;
while(cin>>value){
sum+=value;
}
cout<<"The sum of the values is "<<sum;
return 0;
}
按非法字符或CTRL+Z+enter中止
3159
1126
441

被折叠的 条评论
为什么被折叠?