I was trying to read a lot of numbers dynamically using the code below followed by EOF at the end:
vector<double> data;
double x;
while (cin >> x)
{
data.pushback(x);
}
this method is working great but i would like to know what is happening with the expression below
cin >> x
Yeah, I know that it is used to input the data but how come I’m able to test conditions with it.
What happens with the expression below:
while (cin) or if (cin)
What does cin return?
cinan object of classistreamclass, which can be cast to avoid*, and the returned value is a null pointer if an error occured (this pointer is implicitly convertible tobool).See here for reference.