title: c++ force std::cout flush (print to screen)
body: <p>I have code such as the following:</p>
  
  <pre><code>std::cout &lt;&lt; "Beginning computations..."; // output 1
  computations();
  std::cout &lt;&lt; " done!\n";                  // output 2
  </code></pre>
  
  <p>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 <code>computations()</code> 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.</p>
  
  <p>Is there any way to force the <code>std::cout</code> buffer to get printed before the <code>computations()</code> call?  Alternatively, is there some other way (using something other than <code>std::cout</code>) to print to standard out that would fix this problem?</p>