My answer, today, was edited and std::endl
was changed to \n
.
Does \n
have any advantages?
My answer, today, was edited and std::endl
was changed to \n
.
Does \n
have any advantages?
std::endl
calls flush
stream while cout << "\n"
does not flush the stream, so cout << "\n";
gain better performance, especially while you call it in loop.
§27.7.3.8 Standard basic_ostream manipulators
namespace std {
template <class charT, class traits>
basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
}
1 Effects: Calls os.put(os.widen(’\n’)), then os.flush().
\n
terminates the line. std::endl
terminates the line and flushes the output buffer. In most cases, continually flushing the output buffer merely wastes time.