2

Coding in Visual C, Windows appears to output text with the 1252 code page.

How do you set the code page to something else, e.g. UTF7, from C code? (e.g. what is the API function call?)

I looked at How to Output Unicode Strings on the Windows Console but it doesn't give an exact answer to my specific question.

Also this answer shows how to display the current code page, but doesn't show how to SET the code page from C.

Community
  • 1
  • 1
T. Webster
  • 9,605
  • 6
  • 67
  • 94
  • 1
    No, if you are anywhere close to 1252 then the console encoding will be 437, the olden IBM-PC code page. You change it with SetConsoleCP() – Hans Passant Dec 06 '12 at 02:04
  • @HansPassant, no matter which CP I try for SetConsoleCP(e.g. CP_UTF7, CP_WINAPI), the string will printf to the console exactly the same way. (e.g. 193, 63, 140 single-byte values show up in VS2010 debugger as code page 1252 chars, but oddly enough what actually displays on console is those values printed as unicode 9524, 66, 238). Why is SetConsoleCP not changing how the bytes are displayed? – T. Webster Dec 06 '12 at 16:47
  • 2
    You must pick an 8-bit encoding, CP_UTF8 is a good idea. You must then also change the font to a non-terminal font. Consolas is a good idea. – Hans Passant Dec 06 '12 at 16:53
  • good to know, btw SetConsoleCPOutput *does* work. – T. Webster Dec 06 '12 at 19:21

1 Answers1

2

You must pick an 8-bit encoding, CP_UTF8 is a good idea. You must then also change the font to a non-terminal font. Consolas is a good idea. – Hans Passant

SetConsoleOutputCP

Pablo Montilla
  • 2,941
  • 1
  • 31
  • 35
T. Webster
  • 9,605
  • 6
  • 67
  • 94