【问题标题】:Ncurses wgetnstr russian?Ncurses wgetnstr 俄语?
【发布时间】:2021-05-20 13:56:59
【问题描述】:

我在使用 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 的返回值吗?
  • 上图是输入词,但和描述代码完全一样。还添加了示例不,不检查,我应该吗?
  • 你应该只检查调用的返回值,如果你关心它们是否有效。

标签: c++ linux locale ncurses setlocale


【解决方案1】:

manual page

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

更重要的是,您必须致电 setlocale之前* 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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多