I follow the C ++ programming tutorial and found out about the following code example:
string buf; while (cin >> buf && !buf.empty()) { if (buf[0] != '_') continue;
The loop should ignore words that do not begin with underscores, and do something with those that begin with underscores.
My condition question
(cin >> buf && !buf.empty())
I would say that the condition (! Buf.empty ()) is always true when (cin β buf) is true, so I donβt see the point of adding it. Is there a case where the second condition is not redundant?
There is a previous question about stack overflows around a similar construct ( Is it possible to read an empty string from cin and still get true from cin.good ()? ), Whose answer is simply no (the second condition is redundant).
If this is correct, why is it in the book? Is this just a mistake? Or is there some special situation where a double condition makes sense?
source share