this post was submitted on 05 Apr 2025
161 points (96.0% liked)

Programmer Humor

34853 readers
424 users here now

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

Rules:

founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 7 points 3 days ago (4 children)

No, there's no guarantee that in every context \n is translated portably.

[–] [email protected] 15 points 3 days ago (3 children)

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.

[–] [email protected] 6 points 3 days ago (1 children)

Ahhh, I see. Looks like the magic happens somewhere further down in iostream.

[–] [email protected] 3 points 2 days ago

It's controlled by whether the stream's opened in text mode or binary mode. On Unix, they're the same, but on Windows, text mode has line ending conversion.

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