Printing unicode characters in PowerShell via a C++ program

Question:

My end goal here is to write some non-latin text output to console in Windows via a C++ program.

cmd.exe gets me nowhere, so I got the latest, shiny version of PowerShell (that supports unicode). I’ve verified that I can

  • type-in non-unicode characters and
  • see non-unicode console output from windows commands (like “dir”)

for example, I have this file, “가.txt” (가 is the first letter in the korean alphabet) and I can get an output like this:

So far so good. But writing to console using a C++ program doesn’t work.

I don’t know what I’m missing. The fact that I can type-in and see 가 on the console seems to indicate that I have the three needed pieces (unicode support, font and glyph), but I must be mistaken.

I’ve also tried “chcp” without any luck. Am I doing something wrong in my C++ program?

Thanks!

Answer:

From the printf docs:

wprintf and printf behave identically
if the stream is opened in ANSI mode.

Check out this blog post. It has this nice short little listing:

Source:

Printing unicode characters in PowerShell via a C++ program by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply