Note that there are some explanatory texts on larger screens.

plurals
  1. POHeavy method call blocks cout
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/10554474/why-does-my-cout-output-not-appear-immediately">Why does my cout output not appear immediately?</a> </p> </blockquote> <p>I have a very heavy method (it checks if a number is a prime - Euler 3), which blocks <code>cout</code>.<br> How is this possible? This is my code:</p> <pre><code>int main(int argc, char * argv[]) { cout &lt;&lt; "-----------------------------------------------------------" &lt;&lt; endl; cout &lt;&lt; "isPrime(3): " &lt;&lt; ((isPrime(3)) ? "true" : "false") &lt;&lt; endl; cout &lt;&lt; "isPrime(10): " &lt;&lt; (isPrime(10) ? "true" : "false") &lt;&lt; endl; cout &lt;&lt; "BLAH"; cout &lt;&lt; "BLAH"; cout &lt;&lt; "BLAH"; cout &lt;&lt; "BLAH"; cout &lt;&lt; "BLAH"; cout &lt;&lt; "BLAH"; cout &lt;&lt; "isPrime(600851475143): " &lt;&lt; (isPrime(600851475143.0) ? "true" : "false") &lt;&lt; endl; // This one takes very long to complete cout &lt;&lt; "-----------------------------------------------------------"; } </code></pre> <p>Like this, it outputs:</p> <pre><code>[Session started at 2013-01-19 13:50:12 +0100.] ----------------------------------------------------------- isPrime(3): false isPrime(10): false </code></pre> <p>and then stops (for a few minutes). (<code>isPrime()</code> is broken, I know!) If I comment the line with <code>isPrime(600851475143)</code> out, it outpus everything except the output of the commented line of course in less than a second. </p> <p>How is it possible that a very heavy method call blocks output that should already have been written to <code>cout</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload