title: How to make std::wofstream write UTF-8?
body: <p>I am redirecting <code>std::wclog</code> to a file for logging in my program:</p>
  
  <pre><code>std::wclog.rdbuf((new std::wofstream("C:\\path\\to\\file.log", std::ios::app))-&gt;rdbuf());
  </code></pre>
  
  <p>Logging happens by writing to <code>std::wclog</code>:</p>
  
  <pre><code>std::wclog &lt;&lt; "Schöne Grüße!" &lt;&lt; std::endl;
  </code></pre>
  
  <p>Surprisingly I found that the file is being written in ANSI. (This would be totally acceptable for <code>ofstream</code> and <code>clog</code>, but I had expected <code>wofstream</code> and <code>wclog</code> to produce some kind of unicode output.) I want to be able to log in CYK langugages as well (e.g. user input), so <strong>is there a way to get <code>wofstream</code> to produce UTF-8?</strong> The openmode flags seem not to provide for this.</p>
  
  <p>(If there isn’t a platform-independent way, I am on Win7+ 64-bit.)</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>There is an error in the question above. The line </p>
  
  <pre><code>std::wclog &lt;&lt; "Schöne Grüße!" &lt;&lt; std::endl;
  </code></pre>
  
  <p>should correctly be</p>
  
  <pre><code>std::wclog &lt;&lt; L"Schöne Grüße!" &lt;&lt; std::endl;
  </code></pre>
  
  <p>This is just to demonstrate what I want to do, in real life the <code>wstring</code> being written to the <code>wofstream</code> comes out of a class which provides for translation, like</p>
  
  <pre><code>std::wclog &lt;&lt; _(L"Best regards") &lt;&lt; std::endl;
  </code></pre>
  
  <p>where</p>
  
  <pre><code>#define _(X) i18n::translate(X)
  
  class i18n {
  public:
      static std::wstring translate(const std::wstring&amp;);
  }
  </code></pre>
  
  <p>So what I want to do is to write a <code>wstring</code> to <code>std::wclog</code> using an <code>wofstring</code> to put it into a file, and that file should be UTF-8 encoded (without BOM).</p>