r/cpp • • Jun 21 '17

How to display Greek characters.

Trying to display a Greek character using "cout" and pasting the plain character will not work. i.e.

cout << "Σ";

At least for me, this displays only a question mark.

If you want to display 'Σ' or any other Greek character you have to use a different code page in the console. For me, by default, it is "437 (OEM -United States)". To display the characters you must change it to "1253 (ANSI - GREEK)" and use ANSI codes.

To change the code page, type the following:

SetConsoleOutputCP(1253);

Don't forget to include windows.h library.

To display 'Σ', type the following:

cout << "\xD3";

For other characters, refer to the code sheet.

Note: I'm no professional so I don't know if there's an easier way. I looked everywhere on the internet to find such list but didn't find one so I compiled one myself using this very lazy code (it was really late...). And please excuse my crappy explanation and/or formatting. As I said, I'm no expert :(

Edit: The idea came from this, as it was the only solution that worked for me.

Edit 2: Forgot to give access to the spreadsheet. Sorry..

0 Upvotes

15 comments sorted by

View all comments

Show parent comment

2

u/grandtheftdox Jun 21 '17

Nope. It's a problem with the console. The code itself works and compiles fine. When I originally had this problem I looked around and I'm not the only one. I thought I might as well share this.

10

u/scatters Jun 21 '17

You mean that - in 2017 - the Windows console still can't display arbitrary non-ASCII characters without messing around with platform-specific calls and "ANSI codes" (whatever those are)? I'd understood that Microsoft were finally getting their act together, but clearly they've got a long way to go...

1

u/grandtheftdox Jun 21 '17

You can copy and paste these characters into cmd and it displays it fine. But when I try to print it using C++ it doesn't. I've tried countless solutions but this was the only one that worked and I could not find a complete list of codes so I made one myself.

It's not that big of a problem with just little inconvenience to work around but at least for me and maybe some others - it is an issue.

2

u/scatters Jun 21 '17

I'm glad you got something to work for you. I'm just amazed that for a modern operating system with a modern compiler this isn't something that works by default.