title: Writing utf16 to file in binary mode
body: <p>I'm trying to write a wstring to file with ofstream in binary mode, but I think I'm doing something wrong. This is what I've tried:</p>
  
  <pre><code>ofstream outFile("test.txt", std::ios::out | std::ios::binary);
  wstring hello = L"hello";
  outFile.write((char *) hello.c_str(), hello.length() * sizeof(wchar_t));
  outFile.close();
  </code></pre>
  
  <p>Opening test.txt in for example Firefox with encoding set to UTF16 it will show as:</p>
  
  <p>h�e�l�l�o�</p>
  
  <p>Could anyone tell me why this happens?  </p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Opening the file in a hex editor I get:</p>
  
  <pre><code>FF FE 68 00 00 00 65 00 00 00 6C 00 00 00 6C 00 00 00 6F 00 00 00 
  </code></pre>
  
  <p>Looks like I get two extra bytes in between every character for some reason?</p>