r/cpp • • Mar 29 '19

Don’t Use std::endl

https://accu.org/index.php/journals/2619
0 Upvotes

27 comments sorted by

View all comments

47

u/capn_bluebear Mar 29 '19

This again...the message is way too extreme: there's no problem using `std::endl` outside of performance-critical code (which, in my personal experience, is 99.9% of std::endl usage). _Definitely_ use `std::endl` if a newline+flush is what you want.

If for some reason you need your std:: printing to go faster, definitely avoid flushing at every newline.

2

u/Osbios Mar 29 '19

There also is the issue with output from multiple threads. Mixing up parts of things you intended to output as a single string over multiple lines.

3

u/kalmoc Mar 30 '19

On cout that will happen regardless, because the cout stream object doesn't buffer by default.

0

u/[deleted] Mar 30 '19

[deleted]

1

u/kalmoc Mar 30 '19

You are mixing stream buffering on the OS level (it maybe c level) and buffering in the c++ upstream objects.

1

u/Osbios Mar 30 '19

Interesting, did not know that. But makes sense. Every single << is a function call.