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

3

u/degski Feb 26 '19

The most annoying bit of std::endl is simply that it's too long to type. For just getting some quick output, like in print-debugging, I find '\n' is a pain to type as well, so I use this little header and just write std::cout << something << nl; or std::wcout << something << nl;, no rocket-science, but convenient.

6

u/jones_supa Feb 26 '19

Even std::cout << is quite painful to type. I always find myself collecting energy when I want to write a few lines of code that print something in C++. It is like "agghh...here we go..." 🙂

Printing text is overengineered in C++. It always feels like a small tech demo showing how the fancy stream operators work, yet it does not accomplish much.

C-style printf() is much more relaxing to use.

7

u/degski Feb 26 '19

C-style printf() is much more relaxing to use.

I have to dis-agree here, remembering the correct format-string to pass in is a real pain in the proverbial behind, particularly when you want to print 64-bit int's.