读取数量不定的输入数据

#include<iostream>
using namespace std;
int main()
{
	int sum=0,value=0;
	//读取数据直到文件尾,计算所有读入的值的和
	while(cin>>value) //输入Ctrl+Z并按enter键:Windows中的文件结束符为Ctrl+Z
	{
		sum+=value;
	}
	cout<<"sum is:"<<sum<<endl;
	system("pause");
	return 0;
}

原文地址:https://www.cnblogs.com/zztong/p/6695285.html