Why does std::endl makes this loop run forever?

125 Views Asked by At

I found this code on a q&a platform.

#include <iostream>
int main()
{
for (int i = 0; i < 300; i++)
std::cout << i << " " << i * 12345678 << std::endl;
}

At first sight, this seems normal but instead it runs infinitely. Results at : https://ideone.com/7F88MV

Now I changed the std::endl to "\n" and it behaved normal this time running for 300 times, terminating at i=299.

So what is going on with the std::endl keyword ?

0

There are 0 best solutions below