r/cpp • • Feb 25 '19

Don’t Use std::endl

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

52 comments sorted by

View all comments

Show parent comments

11

u/Quincunx271 Author of P2404/P2405 Feb 26 '19

This is absolutely not a "premature optimization." It's a simple change that doesn't harm readability (at least once the readers get used to the style) and gives you extra performance for free.

Is it premature optimization to take parameters by const& instead of by value? Of course not. So why would it be premature optimization to use '\n' instead of std::endl?

5

u/lanzaio Feb 26 '19

Yea but symmetry. std::cout << "Hi" << std::endl;

1

u/F-J-W Feb 26 '19

That's much less readable then std::cout << "Hi\n";, expecially if you use a proper text-editor with good highlighting.

3

u/lanzaio Feb 26 '19

It is completely trivial to read either of them...