Apologies, I didn't mean to contribute to your being pissed off.
Just because something is not bad if you know what you're doing doesn't make it not hazardous. As an example, a chainsaw is an insanely useful tool and not inherently bad, but it's also hazardous in that you can gravely injure yourself. As for code examples, here are a few:
*
goto
can be used to create very intricate and comparatively efficient flow control (also remains the cleanest way to break out of deeply-nested loops), but misuse can also make code a ball of spaghetti as cooked by a chef in Gordium.
* Putting single statements on a new line after an
if(condition)
reduces line length compared to putting it on a new line and line count compared to wrapping them in traditional braces, but also makes your code prone to problems like this:
https://nakedsecurity.sophos.com/2014/02/24/anatomy-of-a-goto-fail-apples-ssl-bug-explained-plus-an-unofficial-patch/
* Using input without checking whether said input is valid is convenient (and in some cases much more performant), but in the worst case can lead to security issues (like SQL injection).
As it turns out, that "if you know what you're doing" bit is a massive caveat, even for experienced programmers. People make mistakes, wherein they occasionally forget where they're doing. A more defensive approach taken from the get-go can potentially save them from embarrassment (or worse). Consequently, people who teach/mentor programmers generally (should) have an interest in promoting ways of doing things that aren't hazardous, especially to a beginner. Relatedly, that also means disrecommending solutions that are more hazardous/fragile unless they have some property that the person they're being recommended to absolutely needs (and even that will have disclaimers).
I complain about this particular way of using eof() not only because it's part of a known beginner anti-pattern, but because you posted several examples that demonstrate exactly why it's a risky idea. You provided input for them that works obviously, but on slightly different input, they demonstrate non-obvious and potentially-unwanted behavior. It's fine if you intended it, but a) you didn't document it, and b) this is a beginner thread (despite the subforum it's posted in), where people using posted code as an example to refer to is a comment occurrence.
Sorry, but while I agree eof() isn't some devil to avoid at all costs, this simply isn't a good use of it.
-Albatross
P.S. - std::getline, unlike most stream extraction operators, doesn't strip leading whitespace. It does discard the delimiter, which is a newline by default, but that's about it.