title: "\n" or '\n' or std::endl to std::cout?
body: <p>It was many years now since I stopped using <code>std::endl</code> to end lines when writing to <code>std::cout</code>, and started using <code>"\n"</code> instead.</p>
  
  <p>But now I start seeing more snippets of code using <code>'\n'</code> instead, and I started wonder what might be best.</p>
  
  <p>Besides the obvious that one is a string, and the other a character, is there any advantage to using this:</p>
  
  <pre><code>std::cout &lt;&lt; variable &lt;&lt; '\n';
  </code></pre>
  
  <p>Over this:</p>
  
  <pre><code>std::cout &lt;&lt; variable &lt;&lt; "\n";
  </code></pre>
  
  <hr>
  
  <p>Late addition:</p>
  
  <p>When I asked this question I seemed to think that newline <code>'\n'</code> flushed the buffer. Now I know that it <em>depends</em>.</p>
  
  <p>By default <code>std::cin</code> is tied to the old C <code>stdin</code> <code>FILE*</code> stream, and <code>std::cout</code> is tied to <code>stdout</code>. The flushing on newline comes from this tying. By default <code>stdout</code>, if connected to a terminal, is line-buffered. That means a new line will flush its buffers. So when printing a newline using <code>std::cout</code>, that will lead to <code>stdout</code> being flushed.</p>
  
  <p>If <code>stdout</code> is not connected to a terminal (for example the output has been redirected or is piped), or if the tie between <code>std::cout</code> and <code>stdout</code> is broken, then newlines will not flush anything.</p>