0

I want to create a program which is sort of a dictionary for greek words in C++ and I am using CodeBlocks. The problem is that I can't figure out how to read and write non ASCII characters to and from the console and files. I have tried various methods I found online, like using wchar_t, char32_t and more but none of them worked for me.

wchar_t c;
wcin>>c;
wcout<<c<<"\n";

The above code worked for "simple" greek letters, 'α' for example. It did not work with polytonic letters like 'ᾧ'. Specifically, polytonic greek letters appeared as question marks in the console whenever I typed them in.

wchar_t c;
wifstream wfin("test_unicode.txt");
wfin>>c;
wcout<<c<<"\n";

The above code did not work for any input, even latin characters. The output was always blank.

wchar_t c = 'α';
wcout<<c<<"\n";

Also I haven't been able to initialize wchar_t or wstring variables with greek letters within the program, the above code prints nothing on my screen.

Please help!

tsioftas
  • 11
  • 2
  • Are you sure you don't confuse Unicode-32 with UTF-8? – user31264 Oct 05 '16 at 19:05
  • 1
    I suggest you 1. narrow down your question to reading text file with given encoding (btw UTF8 would be much more conventional choice than UTF32, and better supported by editors etc, so overall easier). 2. Verify that input file really is the encoding you want (probably by looking at hex dump of the file). 3. Provide [MVCE](http://stackoverflow.com/help/mcve) trying to read the file. – hyde Oct 05 '16 at 19:20
  • 2
    Another thing, you should test that your terminal can show the chars you want. If it can't, you have to redirect output to file and inspect its hex dump, for example. Reasons for failing to show thise chars are at least, terminal uses encoding which doesn't even have those chars (so they get brutally replaced with question mark chars), or there's no font for those chars (so placeholder glyph is drawn instead). – hyde Oct 05 '16 at 19:22

0 Answers0