gpt4 book ai didi

c++ - eclipse ncurses 和 xterm,打印未知字符

转载 作者:太空宇宙 更新时间:2023-11-04 03:43:01 25 4
gpt4 key购买 nike

我遇到了 打开终端时出错:未知。 使用 ncurses 和 Eclipse Luna。

因此安装了 xterm 并在 Run/Debug Configurations > Environment 中添加 TERM=xterm

现在,当我运行以下简单的“Hello World”应用程序时,Eclipse 控制台中打印出一些奇怪的字符:

enter image description here

代码:

#include <stdio.h>
#include <ncurses.h>

int main() {
initscr(); /* Start curses mode */
printw("Hello World !!!"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
getch(); /* Wait for user input */
endwin(); /* End curses mode */

return 1;
}

这些字符是什么?以及如何删除它们?

最佳答案

这些字符是 initscr() 输出以完成其工作的内容。

终端知道不显示这些字符并以特殊方式解释它们。由于 Eclipse 控制台不是终端,因此它没有任何概念。

如果你想让你的程序在终端和非终端上都工作,你需要检查你的标准输出是否是终端,如果不是,避免使用 ncurses 特定的函数。参见 man isatty

如果您只需要您的程序在终端中运行,就不要使用 Eclipse 控制台。参见 this question and its answer设置说明。

关于c++ - eclipse ncurses 和 xterm,打印未知字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26998910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com