Search code examples
c++endl

Isn't std::endl redundant?


Flush happens in the following cases:

  • std::cerr
  • std::cin
  • program termination
  • in many implementations, standard output is line-buffered, meaning "\n" flushes anyway

So it seems in most regular programs, std::endl is basically unnecessary, but it's used almost everywhere.


Solution

  • So it seems in most regular programs, std::endl is basically unnecessary, but it's used almost everywhere.

    No it's not redundant, since implementation of flushing along '\n' isn't mandated by the standard. That's just an implementation specific behavior, while the behavior of std::endl is always clearly defined.