std::flush
right after a std::endl
is used all over the legacy code I am looking at. When I first saw this, my thought was it is redundant from looking at the description of std::endl
and std::flush
at:
http://en.cppreference.com/w/cpp/io/manip/endl
http://en.cppreference.com/w/cpp/io/manip/flush
Here is an example of what I am seeing in the legacy source code:
std::cout << "Generic Notification" << std::endl << std::flush;
But, as many senior software developers have seen this code throughout the years, I am wondering if there is some detail I am missing. Is there any purpose to having a std::flush
after a std::endl
?
std::cout
but some other stream there might be a reason... – Sidewalkstd::endl
is defined as "end line & flush." – Principallyoperator<<
overloads forstd::endl
andstd::flush
i can make them work any way I want, no? – Sidewalkstd::cout
to otherstd
streams (e.g. astd::ofstream
instance). – Principallystd::cout
for the sake of a mcve. Of course even for a custom streamlike object theflush
should not have any use in that place – Sidewalkflush
if it wasnt a standard stream, though it still wouldnt be a good reason, because a stream that does not flush onendl
can be considered broken – Sidewalksed -ri 's/std::cout (<< .*);$/std::cout \1 << std::flush;/'
on the source at some point. – Wrightson