I am writting a simple C++ programm and I want to generate outputs to the console but with the functions 'fwrite' and 'printf'. However, I can't print special characters like 'á', 'é', ... Here is a simple code:

printf("Special character: 'ñ'");

Were the output was ±
I found that those characters are printed as ascii but they were encoded in Utf8. I don't know how to make this output visible correctly, I'm using the Microsoft Visual Studio. Any help?

4 Years
Discussion Span
Last Post by tinstaafl

I already tried SetConsoleOutputCP(65001); but nothing happended. I also tried WideCharToMultiByte(codepage, 0, unicode, lenW, 0, 0, NULL, NULL); but it wrote 2 characters for each one.


On my system the console seems to use ASCII for output as well. I'm not sure if there is a class that will convert the characters, but you could use the Character Map(Programs/Accessories/SystemTools), and set the character set to DOS and the language of your omputer. That will give you the hex number for the ASCII code.

wChar_t c = 0x99;
wcout << c;

will output Ö on my system.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.