How can I output Unicode characters to the Visual C++ console? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I output Unicode characters to the Visual C++ console?

I tried adding the specific codes for each special character but the console does not interpret and render them correctly. I can type the characters while programming, and those characters are also admitted and later returned through user input on the console, but once I click on the Debugger to run and compile the program the Unicode characters in my output are all mixed up. Is Unicode not supported in Visual Studio IDE? Thanks in advance!

8th Aug 2017, 9:15 AM
Lucía López Otal
Lucía López Otal - avatar
5 Answers
+ 5
You just have to change the font of the console window and use unicode functions... Change your font to something that supports unicode. In default available mono-spaced fonts, Lucida Console will be best for this... The font can be changed by simply right clicking on the small exe icon in the left of the title of the console window, clicking on properties, moving to font tab, and switching the font. Now, you will have to change cout to wcout and string to wstring throughout the program where you print unicode characters. This is as cout and string does not support unicode. Also, unicode strings are preceded by a capital L to differentiate them from non-unicode strings. So type unicode strings in the following format: wstring hello = L"Hello Unicode"; wcout << hello ;
8th Aug 2017, 10:20 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 4
Thank you so much to everyone for your answers and links! @Jojo I accidentally spammed my own question because my Sololearn app displayed an error message related to a connection error so I submitted the question a few times. Thanks for pointing that out!
8th Aug 2017, 11:16 AM
Lucía López Otal
Lucía López Otal - avatar
+ 1
I've searched on the Internet and this is what I found: https://stackoverflow.com/questions/12015571/how-to-print-unicode-character-in-c Question for C language but it also works with C++ If you want to print a character that have the Unicode value U+0444, you can write : cout<<"\u0444"; To know what is the Unicode value, use this table: https://en.m.wikipedia.org/wiki/List_of_Unicode_characters
8th Aug 2017, 9:46 AM
Jojo
+ 1
Ooh! OK! Sorry for the misunderstood ;)
8th Aug 2017, 11:18 AM
Jojo