c++ - How does while (std::cin >> value) work? -
in example given in c++ primer,
#include <iostream> using namespace std; int main() { int sum = 0, value = 0; while (std::cin >> value) { sum += value; // equivalent sum = sum + value } std::cout << "sum is: " << sum << std::endl; return 0; } how (std::cin >> value) return true? , "end of file"? seems must understand term in order understand primary question.
thanks!
the overloaded operator>> function returns reference stream itself, , stream have an overloaded operator allows used in boolean condition see if last operation went okay or not. part of "okay or not" includes end of file reached, or other errors.
Comments
Post a Comment