Here's an example. Let's say you are debugging your code and trying to find out when it crashes. In some cases (it is not guaranteed to happen all the time) the code below doesn't output anything. However, if you use endl instead of '\n', then it should always output the first i = 0 line before it crashes.All flushing means is sending output to the device. So if you are outputting to the console, then just because you say cout << i doesn't mean i is sent to the console right away. It is sent to an output buffer and when the system is ready or is forced to it flushes that output buffer to the console. Calling endl is one way to force it to flush the data to the console.Code:#include <iostream>
#include <ostream>
int main()
{
using namespace std;
int i = 0;
std::cout << "i = " << i << '\n';
int *p = 0;
*p = 3; // this might crash
std::cout << "*p = " << *p << '\n';
}