this post was submitted on 05 Apr 2025
167 points (95.6% liked)

Programmer Humor

35796 readers
140 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
(page 2) 14 comments
sorted by: hot top controversial new old
[–] besselj@lemmy.ca 10 points 1 month ago (3 children)
[–] SpaceNoodle@lemmy.world 18 points 1 month ago (1 children)
load more comments (1 replies)
load more comments (2 replies)
[–] scrubbles@poptalk.scrubbles.tech 12 points 1 month ago (1 children)
load more comments (1 replies)
[–] SpaceNoodle@lemmy.world 46 points 1 month ago* (last edited 1 month ago) (1 children)

If I'm writing C++, I'm usually optimizing for portability over performance, in which case I would prefer std::endl as it would yield the best results regardless of platform; it also keeps the end-of-line character out of other strings, making code just a little cleaner.

\n is for when I'm done pretending that anything that isn't Unix-like is OK, or I'm counting the cycles of every branch instruction.

[–] barubary@infosec.exchange 33 points 1 month ago (6 children)

std::endl provides zero portability benefits. C++ does have a portable newline abstraction, but it is called \n, not endl.

load more comments (6 replies)
[–] savvywolf@pawb.social 5 points 1 month ago
[–] unlawfulbooger@lemmy.blahaj.zone 17 points 1 month ago (5 children)
[–] hellfire103@lemmy.ca 11 points 1 month ago* (last edited 1 month ago) (5 children)

Instead of this:

std::cout << "Hello world.\n";

You can do this:

std::cout << "Hello world." << endl;
load more comments (5 replies)
[–] jaybone@lemmy.zip 2 points 1 month ago

God bless your soul.

[–] allywilson@lemmy.ml 3 points 1 month ago

From memory it's a way to declare a line ending after your string.

[–] vapeloki@lemmy.world 40 points 1 month ago (1 children)

std::endl is used in output streams in C++ to end the line, using the os specific line termination sequence, and flush the buffer.

The later one is a performance issue in many cases, why the use of "\n" is considered preferred

[–] xigoi@lemmy.sdf.org 2 points 1 month ago (2 children)

Don’t most terminals flush the buffer on newline anyway?

load more comments (2 replies)
[–] gon@lemm.ee 7 points 1 month ago (2 children)
[–] unlawfulbooger@lemmy.blahaj.zone 11 points 1 month ago (2 children)

Boy am I glad I don’t do C++ anymore. That string handling with the overloaded bitshift operator was wild.

load more comments (2 replies)
load more comments (1 replies)
load more comments