如何在ncurses中使用get UTF-8重音符号
How to use get UTF-8 accents with ncurses
我最近安装了新的Windows 10版本14393,我想使用新的linux子系统。所以我决定学习ncurses,但我找不到如何从getch
获得像è
这样带有重音的字符的UTF-8代码。这是我的代码:
#include <iostream>
#include <string>
#include <curses.h>
using namespace std;
int main(int argc, char **argv)
{
char ch;
setlocale(LC_ALL, "fr_FR.UTF-8");
initscr();
cbreak();
noecho();
printw("èèèn"); // i can print accents
ch = getch(); // if i press è it gives me 2 characters
printw("%d", ch);
ch = getch();
printw("%d", ch);
getch(); // wait for a key to exit
endwin();
return 0;
}
例如,如果我按è
,它会给我两个字符的代码,即-61
和-88
,那么我如何从UTF-8
表中获得它的代码,也就是232
?我使用ncursesw,这里是我的g++
命令来编译:
g++ file.cxx -o file -lncursesw
我的区域设置配置为fr_fr。UTF-8。谢谢你的回答。
getch()
调用在32位chtype
值中返回8位字符(char
工作不好,但在这种情况下不是问题)。UTF-8是多字节编码,在这种情况下,ncurses将返回字节—每次呼叫一个。
要获得Unicode(宽字符)值,请使用get_wch
,例如
wchar_t ch;
get_wch(&ch);
当然,您应该检查get_wch
的返回值,但它的返回值应该是OK
或ERR
—该字符通过作为参数传递的指针返回。
相关文章:
- HEX值到wchar_t字符(UTF-8)的转换
- Cpp-Tuple使用带有变量的get
- 带有Protobuf序列化的C++Hazelcast:字符串不是UTF-8格式的
- 转换特殊字符(UTF-8)
- 通过 get-Method 访问变量在类外不起作用
- 如何在CPP的给定目录中列出UTF编码的文件名?
- 如何使用 C++将 ISO-2022-KR 编码转换为 UTF-8 编码?
- 为什么无论你输入什么,这"while(cin.get(str,3))"只运行一次?
- 在C++中使用 UTF-8 字符串和字符
- Boost.Asio/OpenSSL HTTPS GET certificate trouble
- C++中是否有任何函数等同于python中字典的get函数?
- 使用istringstearm和get行缓慢读取文件
- 如何将 UTF-8 文本从文件转换为某个可以迭代的容器,并检查每个符号是否为C++字母数字?
- 如何将 c++ get 函数代码转换为 opencv 算法中使用的 python
- 将C++ std::string 转换为 UTF-16-LE 编码的字符串
- 在基于英语的系统上将 UTF-8 路径转换为宽字符会引发异常
- C++ 将 UTF-8 转换为字符串
- 使用 cin.get() 初始化字符数组
- 有关读取 UTF-8 编码文本时 Ifstream get() 方法行为的说明 (C++)
- 如何在ncurses中使用get UTF-8重音符号