Does windows console output characters from locale codepage, but not from a codepage returned by GetConsoleOutputCP function?

  c++, mingw, windows

Here’s a simple code to start with:

#include <stdio.h>
#include <locale.h>
#include <windows.h>

int main ()
{
    unsigned char str [3];

    printf ("LC_ALL:tt%sn", setlocale (LC_ALL, ""));
    printf ("LC_TYPE:t%sn", setlocale (LC_CTYPE, ""));

    printf ("Input CP:t%dn", GetConsoleCP ());
    printf ("Output CP:t%dnn", GetConsoleOutputCP ());

    str [0] = getchar ();
    str [1] = getchar ();
    str [2] = getchar ();

    printf ("%d %d %dn", str[0], str[1], str[2]);
    printf ("%c %c %cn", str[0], str[1], str[2]);

    return 0;
}

Returned locale and encoding are represented on the picture. Let’s say I input some small string: "пр", then press enter. What I expect are codes from OEM 866 encoding for ‘п’ and ‘р’, then 10 pointing at the end of the line, so the output codes are "175 224 10" – because console input encoding is 866, as returned by GetConsoleCP (). And I get what I expect.

Console output

Then I’m trying to output these characters to the console. What I expect are the same characters from input, because, as returned by ‘GetConsoleOutputCP ()’, the output encoding is 866. What I get are the characters from Windows-1251 encoding, which is returned by setlocale function.

So, does windows console output characters from locale codepage, but not from a codepage returned by GetConsoleOutputCP () function?

Source: Windows Questions

LEAVE A COMMENT