3

I'm writing a CLI version of the game Snake in C++, and I want to make the snake look cool using different unicode characters to represent different states of the snake. I am using the following characters : ╔, ╗, ╚, ╝, ═, ║, ⩓, ⩔, ⪡, ⪢.

I originally started programming this in Xcode on my Mac, and had no problem what so ever storing them as const char *s.

Image of game running in Xcode on Macos

Running the same code in Visual Studio on Windows, renders much less beautiful results.

Image of game running on Windows (Visual Studio)

Since discovering this, I've been reading all about Unicode and UTF encoding and still do not understand what I should be doing to make these characters to display properly on both Windows and MacOS.

Harry
  • 193
  • 1
  • 12
  • 3
    The problem isn't so much the "characters" you're writing, as the [code page](https://www.computerhope.com/jargon/c/codepage.htm) Windows is using to render those characters. You can find many links on the subject, for example: https://stackoverflow.com/a/45588456/421195 – paulsm4 Jun 24 '21 at 01:18
  • 1
    This might be more of a windows issue than a C++ issue. You might look for unicode and windows cmd. – KevinO Jun 24 '21 at 01:18
  • There are a ton of questions on StackOverflow related to how to print Unicode output on a Windows console. I'm sure you can find a duplicate if you search. – Remy Lebeau Jun 24 '21 at 01:19
  • @paulsm4 I tried copying the code from that answer and replacing the symbol with "⪢". This printed a question mark in a box, so it didn't quite work. It did say `'initializing': truncation from 'char16_t' to 'char'` in the build out put though. maybe fixing that could fix it. – Harry Jun 24 '21 at 01:34
  • Does this answer your question? [Output unicode strings in Windows console app](https://stackoverflow.com/questions/2492077/output-unicode-strings-in-windows-console-app) – Richard Critten Jun 24 '21 at 01:42
  • the easiest way would be [changing Windows to en_US.UTF-8 locale?](https://stackoverflow.com/a/63454192/995714) – phuclv Jun 24 '21 at 01:42
  • @Eljay it has for years. Did you even click that link? – phuclv Jun 24 '21 at 01:49
  • @Eljay `en_US.UTF-8` is standard in other platforms. The last part is the name of the encoding, not the encoding number" – phuclv Jun 24 '21 at 06:48

0 Answers0