title: Windows Unicode C++ Stream Output Failure
body: <p>I am currently writing an application which requires me to call GetWindowText on arbitrary windows and store that data to a file for later processing. Long story short, I noticed that my tool was failing on Battlefield 3, and I narrowed the problem down to the following character in its window title:
  <a href="http://www.fileformat.info/info/unicode/char/2122/index.htm" rel="noreferrer">http://www.fileformat.info/info/unicode/char/2122/index.htm</a></p>
  
  <p>So I created a little test app which just does the following:</p>
  
  <pre><code>std::wcout &lt;&lt; L"\u2122";
  </code></pre>
  
  <p>Low and behold that breaks output to the console window for the remainder of the program.</p>
  
  <p>Why is the MSVC STL choking on this character (and I assume others) when APIs like MessageBoxW etc display it just fine?</p>
  
  <p>How can I get those characters printed to my file?</p>
  
  <p>Tested on both VC10 and VC11 under Windows 7 x64.</p>
  
  <p>Sorry for the poorly constructed post, I'm tearing my hair out here.</p>
  
  <p>Thanks.</p>
  
  <p>EDIT:</p>
  
  <p>Minimal test case</p>
  
  <pre><code>#include &lt;fstream&gt;
  #include &lt;iostream&gt;
  
  int main()
  {
    {
      std::wofstream test_file("test.txt");
      test_file &lt;&lt; L"\u2122";
    }
  
    std::wcout &lt;&lt; L"\u2122";
  }
  </code></pre>
  
  <p>Expected result: '™' character printed to console and file.
  Observed result: File is created but is empty. No output to console.</p>
  
  <p>I have confirmed that the font I"m using for my console is capable of displaying the character in question, and the file is definitely empty (0 bytes in size).</p>
  
  <p>EDIT:</p>
  
  <p>Further debugging shows that the 'failbit' and 'badbit' are set in the stream(s).</p>
  
  <p>EDIT:</p>
  
  <p>I have also tried using Boost.Locale and I am having the same issue even with the new locale imbued globally and explicitly to all standard streams.</p>