How to read unknown number of inputs?
问题 I am learning C++ using the book C++ Primer. In Section 1.4.3 , the following example code about reading the unknown number of inputs is given. #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; } According to the book, if we give an input of 3 4 5 6 , the output will be Sum is: 18 But