\r\n gang
Programmer Humor
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
If I'm writing C++, I'm usually optimizing for portability over performance, in which case I would prefer std::endl as it would yield the best results regardless of platform; it also keeps the end-of-line character out of other strings, making code just a little cleaner.
\n is for when I'm done pretending that anything that isn't Unix-like is OK, or I'm counting the cycles of every branch instruction.
std::endl provides zero portability benefits. C++ does have a portable newline abstraction, but it is called \n
, not endl.
What the heck is endl???
Instead of this:
std::cout << "Hello world.\n";
You can do this:
std::cout << "Hello world." << endl;
God bless your soul.
From memory it's a way to declare a line ending after your string.
std::endl
is used in output streams in C++ to end the line, using the os specific line termination sequence, and flush the buffer.
The later one is a performance issue in many cases, why the use of "\n"
is considered preferred
Boy am I glad I don’t do C++ anymore. That string handling with the overloaded bitshift operator was wild.