I read this line and I don't understand what it does:
if(cout<<X) //What does this mean?
{
...
}
It writes X to cout and checks to see if the stream is still in a good state. It is the same as
cout << X;
if (cout) {
// ....
}
This works because the result of stream << value is a reference to the stream. This is also why you can do things like
stream << x << y << z;
since it is the same as
((stream << x) << y) << z;
In C++, the iostream insertion and extraction operators << and >> return the object on which they were invoked (i.e. their left-hand argument). So if(cout<<X) first inserts X into the cout stream, then uses that stream as a conditional. And iostreams, when tested as booleans, report their status: true if OK, false if in an error state.
So the whole thing means "Print X and then run the following code if cout has no error."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With