title: mixing cout and printf for faster output
body: <p>After performing some tests I noticed that <code>printf</code> is much faster than <code>cout</code>. I know that it's implementation dependent, but on my Linux box <code>printf</code> is 8x faster. So my idea is to mix the two printing methods: I want to use <code>cout</code> for simple prints, and I plan to use <code>printf</code> for producing huge outputs (typically in a loop). I think it's safe to do as long as I don't forget to flush before switching to the other method:</p>
  
  <pre><code>cout &lt;&lt; "Hello" &lt;&lt; endl;
  cout.flush();
  
  for (int i=0; i&lt;1000000; ++i) {
      printf("World!\n");
  }
  fflush(stdout);
  
  cout &lt;&lt; "last line" &lt;&lt; endl;
  cout &lt;&lt; flush;
  </code></pre>
  
  <p>Is it OK like that?</p>
  
  <p><strong>Update:</strong> Thanks for all the precious feedbacks. Summary of the answers: if you want to avoid tricky solutions, simply stick with <code>cout</code> but don't use <code>endl</code> since it flushes the buffer implicitly (slowing the process down). Use <code>"\n"</code> instead. It can be interesting if you produce <em>large</em> outputs.</p>