0

I'm trying to make simple multilingual Windows console app just for educational purposes. I'm using c++ lahguage with WxDev-C++/minGW 4.6.1 and I know this kind of question was asked like million times. I'v searched possibly entire internet and seen probably all forums, but nothing really helps.

Here's the sample working code:

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    /* English version of Hello world */
    wchar_t EN_helloWorld[] = L"Hello world!";
    wcout << EN_helloWorld << endl;

    cout << "\nPress the enter key to continue...";
    cin.get();
    return 0;
}

It works perfectly until I try put in some really wide character like "Ahoj světe!". The roblem is in "ě" which is '011B' in hexadecimal unicode. Compiler gives me this error: "Illegal byte sequence."

Not working code:

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    /* Czech version of Hello world */
    wchar_t CS_helloWorld[] = L"Ahoj světe!"; /* error: Illegal byte sequence */
    wcout << CS_helloWorld << endl;

    cout << "\nPress the enter key to continue...";
    cin.get();
    return 0;
}

I heard about things like #define UNICODE/_UNICODE, -municode or downloading wrappers for older minGW. I tried them but it doesn't work. May be I don't know how to use them properly. Anyway I need some help. In Visual studio it's simple task.

Big thanks for any response.

M.M
  • 138,810
  • 21
  • 208
  • 365
chrisLS
  • 1
  • 1

2 Answers2

1

Apparently, using the standard output streams for UTF-16 does not work in MinGW.

I found that I could either use Windows API, or use UTF-8. See this other answer for code samples.

Community
  • 1
  • 1
M.M
  • 138,810
  • 21
  • 208
  • 365
0

Here is an answer, not sure this will work for minGW.

Also there are some details specific to minGW here

Community
  • 1
  • 1
mzzzzb
  • 1,422
  • 19
  • 38