0

I have printed out a tic-tac-toe table in which I have used the greek alphabets as the numbers to be replaced by the numbers (I would ask the person to replace the greek alphabet with a cross (X) or a circle(0) just like a typical tic-tac-toe game.)

LOL I am having difficulties printing out the greek characters. I am using their unicode value to print them out. But its giving nonsense results (yellow image is he output). How do I fix this?(IN CODE::BLOCKS)

#include <iostream>
using namespace std;
int main(){
 char a = '\u03b1';
    char b = '\u03b2';
    char c = '\u03b3';
    char d = '\u03b4';
    char e = '\u03b5';
    char f = '\u03b6';
    char g = '\u03b7';
    char h = '\u03b8';
    char i = '\u03b9';



    cout<< "               |               |               "<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "      "<<a<<"        |      "<<b<<"        |      "<<c<<"        "<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "_______________|_______________|_______________"<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "      "<<d<<"        |      "<<e<<"        |      "<<f<<"        "<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "_______________|_______________|_______________"<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "      "<<g<<"        |      "<<h<<"        |      "<<i<<"        "<<endl;
    cout<< "               |               |               "<<endl;
    cout<< "               |               |               "<<endl;
}

enter image description here

  • Does this answer your question? [How to print Unicode character in C++?](https://stackoverflow.com/questions/12015571/how-to-print-unicode-character-in-c) – JHBonarius Oct 31 '20 at 16:28
  • I actually did the same (refer to the code) but the output for alpha, beta, gamma and many more are wrong :( – Krrishkutta Oct 31 '20 at 16:37
  • 1
    The console must be set to display these characters. Did you do that? (and it may differ, depending on the platform). You really should post a [mcve], not just the `cout` lines. – PaulMcKenzie Oct 31 '20 at 16:41
  • 1
    This is not doing what you think: `char b = '\u03b2';` The char type only holds an 8 bit value (this unicode character is multi byte) so the value of b is a truncated version of the unicode character. You will need to use a string. `std::string b = "\u03b2";` – Martin York Oct 31 '20 at 19:13
  • You can try to use `wchar_t` type instead of `char` to store the wide characters. It _might_ work, but this all depends on the compiler, the OS and the console configuration... – prapin Oct 31 '20 at 21:32

0 Answers0