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)

Cătălina Sîrbu
  • 1,253
  • 9
  • 30
  • The Windows console is just a basic terminal. The limited range of characters it displays are governed by the code page selected (somewhere). – Weather Vane Jan 02 '21 at 20:59

1 Answers1

0

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

Cătălina Sîrbu
  • 1,253
  • 9
  • 30
  • 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? – AmigoJack Jan 02 '21 at 22:01
  • 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 – Cătălina Sîrbu Jan 03 '21 at 11:14
  • I highly doubt that your IDE actually uses your chosen font for that character, but instead does [font substitution](https://en.wikipedia.org/wiki/Font_substitution), while the console really only uses one font. You can also see this feature when using *Word*. – AmigoJack Jan 03 '21 at 14:26