I have code such as the following:
std::cout << "Beginning computations..."; // output 1
computations();
std::cout << " done!\n"; // output 2
The problem, however, is that often output #1 and output #2 appear (virtually) simultaneously. That is, often output #1 does not get printed to the screen until after computations()
returns. Since the entire purpose of output #1 is to indicate that something is going on in the background (and thus to encourage patience from the user), this problem is not good.
Is there any way to force the std::cout
buffer to get printed before the computations()
call? Alternatively, is there some other way (using something other than std::cout
) to print to standard out that would fix this problem?
std::endl
is pretty popular for this kinda thing... – Leastfprintf()
,std::flush
(as below), or modify his version ofcout
to automatically flush at the end of each line of code... I had a SO thread for that last one but seem to have lost it. – Leastcomputation
function with onecout
line. but it is printing that"Beginning computations..."
before calling the function. but I need to find at which particular case buffer will not free. – Magenmagena