0

I tried setlocale, wchar, usual char... how to define:

char c = '☻'
cout << c << endl;

to print onto console anething (this is relevant to VS2012 and http://ideone.com/LJtDUz)

DuckQueen
  • 772
  • 10
  • 62
  • 134

1 Answers1

0

The problem is that windows by default does not handle Unicode characters and the windows console is not able to display them.

A solution I found at This CPP Thread is as follows:

#include <fcntl.h>
#include <io.h>
#include <iostream>

int
main(int argc, char* argv[])
{
    wchar_t* c = L"☻"; /* needed because the project is using 'Unicode Character Set' */

    _setmode(_fileno(stdout), _O_WTEXT); /* set stdout to UTF16 */
    std::wcout << c << std::endl; /* use a wide cout call to output characters */

    getchar();

    return 0;
}

When you try and use the symbol directly in your code, windows will tell you that i needs to convert your files to Unicode, make sure to accept that and use Unicode Character Set as your projects character set type.

Serdalis
  • 10,296
  • 2
  • 38
  • 58
  • Surprised that works. VS silently swap ansi for unicode for chars? – user4581301 Sep 16 '15 at 03:48
  • @user4581301 Honestly I'm not 100% happy this answer explains everything (even though it is correct), so i'm looking up what exactly is happening in the depths right now. – Serdalis Sep 16 '15 at 03:53
  • 2
    "sequence \x002 is the unicode representation of the smiley face". No it's not. It's a control character that the original IBM PC happened to display as a smiley face back in 1980s before Unicode was ever invented. Microsoft OSes continue to emulate it to this very day. It has nothing to do with the Unicode character ☻. – n. m. could be an AI Sep 16 '15 at 04:14
  • @n.m. Thanks for the comment you are correct, I will delete that part of the answer. I have come across an actual answer which I will post shortly. – Serdalis Sep 16 '15 at 04:16