1.4.3 读取数量不定的输入数据

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qit1314/article/details/89925869

书中页数:P13
代码名称:mysum.cc

     #include <iostream> 
    
    int main() 
    {
    	int sum = 0, value = 0;
    
    	// read until end-of-file, calculating a running total of all values read
    	while (std::cin >> value) 
    		sum += value; // equivalent to sum = sum + value
    
    	std::cout << "Sum is: " << sum << std::endl;
    	return 0;
    }

猜你喜欢

转载自blog.csdn.net/qit1314/article/details/89925869
今日推荐