0

I'm running CodeBlocks in Windows 10 and even after following some of the indications found on SO, I did not manage to print in cosole utf8 chars.

_setmode(_fileno(stdout), 0x00020000); // _O_U16TEXT
setlocale(LC_ALL, "C.UTF-8");

wchar_t star = 0x2605;
wchar_t st = L'★';

if (printf("%lc\n", star) < 0) {
    perror("printf");
}

    if (printf("\n%lc\n", st) < 0) {
    perror("printf");
}

gives the output

printf: Invalid argument
printf: Invalid argument

The console Properties >> Font is set to Lucida Console, similar to codeblocks code editor. I am able to see the star as a symbol inside my text editor but not in the console. What should I do?


EDIT:

even if I change the previous code to:

if (wprintf(L"%lc", star) < 0) {
    perror("printf");
}

printf("\n");

    if (wprintf(L"%lc", st) < 0) {
    perror("printf");
}

I am not able to see more than two rectangles instead of the stars (which if I copy and try to paste them here, are drawn in the right way)

1
  • The Windows console is just a basic terminal. The limited range of characters it displays are governed by the code page selected (somewhere). Commented Jan 2, 2021 at 20:59

1 Answer 1

0

After trying all of my available fonts in the console, the only one which let me see the actual star is SimSun-ExtB.

Sign up to request clarification or add additional context in comments.

3 Comments

What is your actual problem? The console not treating UTF-16 as expected? Not knowing what UTF-8 is and what a Unicode character is? That each font is limited in what it can display?
In the IDE and in the consolde, using the same font, I am not able to see unicode chars. I had to find another font, which I found after posting the question, in order to be able to see the star in the console
I highly doubt that your IDE actually uses your chosen font for that character, but instead does font substitution, while the console really only uses one font. You can also see this feature when using Word.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.