微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ncurses wgetnstr 俄语?

如何解决Ncurses wgetnstr 俄语?

我在使用 ncurses 时遇到了麻烦,尤其是,我无法找到一种方法使其与俄语输入一起使用。我已经尝试过的东西:

  • 使用 ncursesw 链接
  • 设置语言环境(setlocale(0,"") 或 setlocale(LC_ALL,"Russian"))

这都没有奏效,我唯一得到的是:

this

仅使用纯 mvwprintw 也无济于事

 :( here ):

代码本身:

    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,但仍然不起作用

解决方法

manual page

库使用调用程序已初始化的语言环境。

更重要的是,您必须调用 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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?