title: why cerr flushes the buffer of cout
body: <pre><code>#include &lt;iostream&gt;
  using std::cout;
  using std::endl;
  using std::cerr;
  #include &lt;cstdio&gt;
  
  int   main( )
  {
      char pbuffer[BUFSIZ];
      setbuf(stdout, pbuffer);
      cout &lt;&lt; "hello cout" ;
      sleep(5);
      cerr &lt;&lt; "hello cerr";
      sleep(5);
      cout &lt;&lt; "\nAll   done " &lt;&lt; endl;
      sleep(5);
      return 0;
  }
  </code></pre>
  
  <p>after I compile and run the program above, it's output is :</p>
  
  <pre><code>hello couthello cerr
  All   done 
  </code></pre>
  
  <p>but I think it should be:</p>
  
  <pre><code>hello cerrhello cout
  All   done 
  </code></pre>
  
  <p>I want to know, why <code>cerr</code> flushes the buffer of <code>cout</code> ?</p>