Character Encoding Problem

Hi,

I am developing a C ++ project where I want to use symbols like á é õand ┌ ─ ┐ │to draw a couple of beautiful frames. My doubt is that I have to change the code / project in my settings, as without any changes the console simply prints pseudo-random characters.

I know that the above characters are defined in the Code page 437 aka Extended ASCII character set, but what should I know?

After some research, I included the instruction setlocale(LC_CTYPE, "");, and now I can print accented characters (à é õ), but I can not print borders.

Furthermore, it should be used charand stringor wcharand wstringfor the use of these symbols?

thank

+3
source share
3 answers

I think the best way to do this is to use wchar and wstring for characters - they are intended for local independent string operations and are defined as UTF-16 on Windows and as UTF-32 on Linux.

Note that you need to use the appropriate functions, for example wprintfinstead printf... If you use iostream, I think this should work ready using wstrings.

EDIT: Note that it wchar_tdoes not require unicode (in practice this often happens). If wchar_t(and therefore wstring) is unicode, then the C99 standard (and therefore most likely the C ++ standard) indicates what __STDC_ISO_10646__needs to be defined.

, __STDC_ISO_10646__ , wchar_t unicode - (UTF-16 UTF-32), sizeof (wchar_t).

+2
0

, , http://unicode.org/charts/ "Draw Drawing". , CP 437, . : .

0

Source: https://habr.com/ru/post/1771113/


All Articles