title: C++ Printing special ascii characters to the Windows console
body: <p>After 2 hours of searching and trying various methods, I'm pulling my hair out trying to print special ascii characters to the console! (C++)</p>
  
  <pre><code>typedef unsigned char UCHAR;
  
  int main()
  {
    UCHAR c = '¥';
    cout &lt;&lt; c;
  
    return 0;
  }
  </code></pre>
  
  <p>Why does this code print Ñ (209) instead of ¥ (165)???</p>
  
  <p>I've tried:</p>
  
  <pre><code>SetConsoleCP(CP_UTF8);
  SetConsoleOutputCP(CP_UTF8);
  </code></pre>
  
  <p>but neither seems to do anything, no matter which values I pass to it.</p>
  
  <p>Someone else suggested that the console's font needed to be changed through the registry. But that's ridiculous. I don't want my end users to have to start changing registry values simply to run my program...</p>
  
  <p>the really odd thing is that if I print all the ascii characters to a file (using ofstream), they show up correctly both in notepad, and the visual studio editor (2012 professional).</p>
  
  <pre><code>ofstream file("ASCII.txt");;
  if (file.is_open())
  {
      UCHAR c = 0;
      for (int i = 0; i &lt; 256; i++)
      {
          c++;
          file &lt;&lt; c &lt;&lt; "\t|\t" &lt;&lt; (int)c &lt;&lt; endl;
      }
  }
  file.close();
  </code></pre>
  
  <p>Any help is much appreciated.
  Thanks!</p>