I'm new to C++ and as far as I know that using escape sequence '\n'
will not flush the output buffer (as it happens when using endl
), but in my case when debugging the following program using F11 (step into) under qt-creator on Ubuntu 14.04, the output of the function (which is 5
) is directly being printed to the console.
#include <iostream>
void printValue(int nValue)
{
std::cout << nValue << '\n';
}
int main()
{
using namespace std;
printValue(5);
return 0;
}
When I removed the '\n'
from the output in line no. 5, the output postponed till the end of the execution.
- Why is this?