I thought they were the same thing, but when I sent a code to an online judge (with endl(cout)) it gave me “Wrong answer” verdict, then I tried to send another with cout << endl and the judge accepted the code! Does anyone know the difference between those commands?
I thought they were the same thing, but when I sent a code to
Share
There is none that I know of.
std::endlis a function that take a stream and return a stream:When you apply it to
std::cout, it just applies the function right away.On the other hand,
std::basic_ostreamhas an overload ofoperator<<with the signature:which will also apply the function right away.
So, technically, there is no difference, even though stream
std::cout << std::endlis more idiomatic. It could be that the judge bot is simplistic though, and does not realizes it.