Many C++ books contain example code like this...
std::cout << \"Test line\" << std::endl;
...so I\'ve always done that too. But
The difference can be illustrated by the following:
std::cout << std::endl;
is equivalent to
std::cout << '\n' << std::flush;
So,
std::endl If you want to force an immediate flush to the output.\n if you are worried about performance (which is probably not the case if you are using the << operator).I use \n on most lines.
Then use std::endl at the end of a paragraph (but that is just a habit and not usually necessary).
Contrary to other claims, the \n character is mapped to the correct platform end of line sequence only if the stream is going to a file (std::cin and std::cout being special but still files (or file-like)).