如何解决Ncurses wgetnstr 俄语?
我在使用 ncurses 时遇到了麻烦,尤其是,我无法找到一种方法使其与俄语输入一起使用。我已经尝试过的东西:
- 使用 ncursesw 链接
- 设置语言环境(setlocale(0,"") 或 setlocale(LC_ALL,"Russian"))
这都没有奏效,我唯一得到的是:
仅使用纯 mvwprintw 也无济于事
代码本身:
mvwprintw(stdscr,4,base,"Enter description: ");
char *input2 = (char *)malloc(100000);
wgetnstr(stdscr,input2,100000);
string n_description = input2;
更新: 最小的、可重现的示例:
#include <string>
#include "ncurses.h"
#include <clocale>
using namespace std;
int main(){
initscr();
start_color();
use_default_colors();
curs_set(0);
keypad(stdscr,true);
if(setlocale(LC_ALL,"uk_UA.utf8") == nullptr){
endwin();
cout << "Error setting locale\n";
return -100;
}
char *input = (char *)malloc(1000);
wgetnstr(stdscr,input,1000000000);
endwin();
}
UPD2: 检查 setlocale,返回不是 NULL,但仍然不起作用
解决方法
库使用调用程序已初始化的语言环境。
更重要的是,您必须调用 setlocale
before* initscr
。像这样:
#include <stdlib.h>
#include <string>
#include "ncurses.h"
#include <clocale>
#include <iostream>
using namespace std;
int main(){
if(setlocale(LC_ALL,"uk_UA.utf8") == nullptr){
cout << "Error setting locale\n";
return -100;
}
initscr();
start_color();
use_default_colors();
curs_set(0);
keypad(stdscr,true);
char *input = (char *)malloc(1000);
wgetnstr(stdscr,input,1000000000);
endwin();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。