2 ms·
When I want to flush, I use std::flush. Nothing about "endl" screams "this flushes", which is why nobody uses it. Also, flushing on every newline is a needless
by humanrebar 4y ago
When I want to flush, I use std::flush. Nothing about "endl" screams "this flushes", which is why nobody uses it. Also, flushing on every newline is a needless pessimization. Not that performance is everything, but it doesn't buy you much here.
endl just saves you from getting out of the habit of using endl, really.
- Kranar 4y ago>Nothing about "endl" screams "this flushes", which is why nobody uses it. Are you seriously suggesting no one uses std::endl? A simple search on Github actually reveals the opposite... almost everyone uses std::endl and almost no one uses std::flush (94% use std::endl, and 6% use std::flush). I am also in the std::endl camp and find it absurd when people bike shed over it. It's the most intuitive/least surprising behavior (based on Stack overflow questions) and how almost all other mainstream languages behave (flush on new line), and as such it should be the default choice. The use of ... << '\n' << std::flush is best when you want to explicitly call out that behavior because of performance reasons or some other exceptional circumstance.
- UncleOxidant 4y ago> Also, flushing on every newline is a needless pessimization. Maybe, but when you're debugging it's essential. Those debugging cout's aren't going to be there in production.