【问题标题】:Ncurses No OutputNcurses 无输出
【发布时间】:2014-03-02 23:38:14
【问题描述】:
  • 平台:Linux 3.2.0 x86 (Debian Wheezy)
  • 编译器:GCC 4.7.2 (Debian 4.7.2-5)

我正在编写一个需要 ncurses 提供的高级终端控制的程序,但我无法让我的程序将任何内容打印到 stdscr。例如,如果我编译了以下代码,我将不会在屏幕上看到“Testing..Testing”。我以前用过ncurses,从来没有遇到过这样的问题。我不知道这是否相关,但我正在运行全新安装的 Debian(我实际上是在几个小时前安装的)。

#include <ncurses.h>

int main()
{
    initscr();
    printw("Testing... Testing");
    refresh();
    return;
}

上面的程序也是用编译的,

gcc --all-warnings --extra-warnings -std=c11 filename.c -lncurses

【问题讨论】:

  • 它是否清除了initscr() 上的屏幕?您是否尝试在退出 main 之前调用 endwin()

标签: c ncurses


【解决方案1】:

如果您想查看文本,也许您应该在打印时保持程序运行。

#include <ncurses.h>

int main()
{
    initscr();
    printw("Testing... Testing");
    refresh();
    getch(); // Wait the user input in order to keep the program active and showing text.
    endwin(); // Terminate the window to clean all memory allocations.
    return;
}

您可以获取有关 ncurses "hello world" 的更多信息:http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/helloworld.html

【讨论】:

  • +1 这是因为ncurses 清除了initscr() 上的屏幕并在退出时恢复它,所以如果没有getch if 只会闪过
  • 好吧,我觉得自己像个智障,这解决了我的问题。非常感谢
猜你喜欢
  • 1970-01-01
  • 2015-05-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-11
  • 1970-01-01
  • 2012-03-01
  • 1970-01-01
相关资源
最近更新 更多