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

1

u/dpsi Feb 26 '19

If you look at one of the implementations reffered to in the article (specifically Kuhl12) you will see why that isn't the full solution.

4

u/raevnos Feb 26 '19 edited Feb 26 '19

... It's how you print a newline after printing something that isn't a string literal where you can put the \n at the end. I suppose you could use "\n" instead of '\n', but using a string literal to print a single character is something I've always thought was pretty silly.

I have no idea what that has to do with the article you mention, which is about how flushing is slow.

If you're talking about using it with wide streams, you'd just use a L'\n'.

0

u/dpsi Feb 26 '19

If you're talking about using it with wide streams, you'd just use a L'\n'.

That's exactly what I'm talking about, there should be a standard way to write a new line without flushing the stream. It should work without the user having to know about the underlying stream as std::endl does.

6

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

L'\n' is not needed. operator<< automatically widens the character with theostream.widen(c): https://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt2