title: How to portably write std::wstring to file?
body: <p>I have a <code>wstring</code> declared as such:</p>
  
  <pre><code>// random wstring
  std::wstring str = L"abcàdëefŸg€hhhhhhhµa";
  </code></pre>
  
  <p><strike>The literal would be UTF-8 encoded, because my source file is.</strike></p>
  
  <p>[EDIT: According to Mark Ransom this is not necessarily the case, the compiler will decide what encoding to use - let us instead assume that I read this string from a file encoded in e.g. UTF-8]</p>
  
  <p>I would very much like to get this into a file reading (when text editor is set to the correct encoding)</p>
  
  <pre><code>abcàdëefŸg€hhhhhhhµa
  </code></pre>
  
  <p>but <code>ofstream</code> is not very cooperative (refuses to take <code>wstring</code> parameters), and <code>wofstream</code> supposedly needs to know locale and encoding settings. I just want to output this set of bytes. How does one normally do this?</p>
  
  <p>EDIT: It must be cross platform, and <strong>should not rely on the encoding being UTF-8</strong>. I just happen to have a set of bytes stored in a <code>wstring</code>, and want to output them. It could very well be UTF-16, or plain ASCII.</p>