whats the difference between \n and endl they both do the same thing?
Printable View
whats the difference between \n and endl they both do the same thing?
endl prints a newline AND flushes the output stream.Quote:
Originally Posted by lilhawk2892
so you can do
and your output may or may not get to 66 depending on your systems buffering.Code:for (int i = 0; i < 200; ++i)
{
cout << i << '\n';
if (i == 66)
{
// crash here
ASSERT(false);
}
}
but if you do
you're guarenteed to get 0-66 printed out. Of course, flushing the buffer causes a slight performance penalty. Profile to find out if it affects you.Code:for (int i = 0; i < 200; ++i)
{
cout << i << endl;
if (i == 66)
{
// crash here
ASSERT(false);
}
}
Another way to put it
endl is the same as this:
Code:cout << "\n"; cout. flush();