0

How can I display Greek characters and strings, using plain C++ and VS 2008 Express?

Here is the code:

#include <iostream>

int main()
{
    std::cout << 'Φ' << std::endl;
    std::cout << 'Ξ' << std::endl;
    std::cout << "Καλημέρα" << std::endl;

    std::cin.get();
    return 0;
}

by the way i am getting warnings like below

1>d:\02_visualstudio2008projects\displaygreek\displaygreek\displaygreek.cpp(5) : warning C4566: character represented by universal-character-name '\u03A6' cannot be represented in the current code page (1252)
WGS
  • 13,969
  • 4
  • 48
  • 51
DimZon
  • 23
  • 4

1 Answers1

0

There are two ways you can approach this.

Method #1: Embedded unicode

This is useful for those who have a keyboard that allows direct input of unicode characters. You can define a variable like this:

char a = 'ф';

All this requires is that the encoding of your source file is set to UTF-8.

Method #2: Universal Character Names (UCNs)

With this method, you use coded form \u# where the # is the UCN.

char a = '\u0444';

A good place to find the UCN values is here.

Some code samples taken from here.

Community
  • 1
  • 1
phantom
  • 1,457
  • 7
  • 15
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Seitaridis Oct 31 '14 at 21:02
  • @Seitaridis My apologies. I'm paranoid about plagiarism. I'll edit my answer. – phantom Oct 31 '14 at 21:04
  • And i guess, strings will be treated as char arrays, is that so? By the way, there are 3 UTF-8 codepages available, all of them produce the same uglly outputs as before with Greek codepages. – DimZon Oct 31 '14 at 21:35
  • @DimZon It's possible that could be due to your console's font not supporting unicode...not necessarily a coding error. – phantom Oct 31 '14 at 21:36
  • How can i check this out? – DimZon Oct 31 '14 at 21:39
  • @DimZon I'm not sure...it's not really within the scope of this question or SO. – phantom Oct 31 '14 at 21:40
  • @DimZon Your original question was answered already. – phantom Oct 31 '14 at 21:40
  • Thank you for your "clean" answer. I will accept it and try some more investigation about the console – DimZon Oct 31 '14 at 21:42