this post was submitted on 05 Apr 2025
160 points (94.9% liked)
Programmer Humor
34843 readers
16 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
std::endl provides zero portability benefits. C++ does have a portable newline abstraction, but it is called
\n
, not endl.No, there's no guarantee that in every context \n is translated portably.
The same is true of std::endl. std::endl is simply defined as
<< '\n' << std::flush
; nothing more, nothing less. In all cases where endl gives you a "properly translated" newline, so does\n
.Yeah it's an artificial dichotomy based on a popular misconception of what std::endl is and how \n is interpreted.
Ultimately it does not ask about line endings, but about flushing, which is a completely orthogonal question.