Printing Korean in C ++ Console

I'm having trouble printing Korean. I tried various methods to no avail. I tried

one.

cout << "ν•œκΈ€" << endl; 

2.

  wcout << "ν•œκΈ€" << endl; 

3.

  wprintf(L"ν•œκΈ€\n"); 

4.

  setlocale(LC_ALL, "korean"); wprintf("ν•œκΈ€"); 

and much more. But all these prints are Γ­ β€’ Ε“ΓͺΒΈ. I am using the MinGW compiler, and my OS is Windows 7.

PS Strange Java prints Korean fine,

  String kor = "ν•œκΈ€"; System.out.println(kor); 

working.

+7
c ++
source share
2 answers

Set utf-8 console code page before printing text

 ::SetConsoleOutputCP(65001) 
+1
source share

Since you are using Windows 7, you can use WriteConsoleW, which is part of the windows API. #include <windows.h> and try the following code:

 DWORD numCharsToWrite = str.length(); LPDWORD numCharsWritten = NULL; WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str.c_str(), numCharsToWrite, numCharsWritten, NULL); 

where str is std :: wstring

Read more about WriteConsoleW: https://msdn.microsoft.com/en-us/library/windows/desktop/ms687401%28v=vs.85%29.aspx

After using other methods, this worked for me.

0
source share

All Articles