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

Popular posts from this blog

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -

c# - Populating Gridview inside Listview ItemTemplate On Web User Control from Code Behind -