如何正确使ncurses的显示UTF-8字符用C? [英] How to make ncurses display UTF-8 chars correctly in C?
问题描述
我已经写在C使用ncurses的程序。它让用户输入和显示。它没有,如果用户输入字符的utf8正确显示。
I have a program written in C using ncurses. It let user input and display it. It does not display correctly if user input utf8 chars.
我救的字符用户inputed到一个文件中。我和猫
这个文件直接在壳牌,它正确显示。
I saved the chars user inputed to a file. And I cat
this file directly in Shell, it display correctly.
我搜索计算器和谷歌,并尝试多种方法,如用ncursesw链接,显示不正确。
I searched stackoverflow and google, and tried several methods, such as link with ncursesw, display incorrectly.
和I LDD /usr/bin/screen$c$c>:<$c$c>libncurses.so.5 =&GT; /usr/lib64/libncurses.so.5
屏幕
能正确显示哪些用户输入。
screen
can display what user input correctly.
如何正确使ncurses的显示UTF-8字符?
How to make ncurses display UTF-8 chars correctly ?
什么是显示使用C中的ncurses UTF-8字符的一般方式?
What is the general way to display UTF-8 chars in C using ncurses?
推荐答案
您需要有一个名为的setlocale(LC_CTYPE,);
(用UTF-8的区域设置初始化之前ncurses的配置)。您还需要确保你的ncurses实际上是与宽字符支持(ncursesw),但对现代发行版内置这是默认/只建。
You need to have called setlocale(LC_CTYPE, "");
(with a UTF-8 based locale configured) before initializing ncurses. You also need to make sure your ncurses is actually built with wide char support ("ncursesw") but on modern distros this is the default/only build.
这篇关于如何正确使ncurses的显示UTF-8字符用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!