英文:
my ncurses window isn't appearing on my terminal
问题
#include <iostream>
#include <ncurses.h>
using namespace std;
int main() {
initscr();
int h, w, y, x;
h = 10;
w = 25;
y = 15;
x = 20;
WINDOW *win = newwin(h, w, y, x);
box(win, 0, 0);
wrefresh(win);
printw("Hello");
wprintw(win, "hi");
wrefresh(win);
getch();
refresh();
endwin();
return 0;
}
英文:
I'm new to Ncurses and I tried to make a program in C++ that makes a window then displays a box and text on both the box and standard screen.
Here is my code
#include <iostream>
#include <ncurses.h>
using namespace std;
int main(){
initscr();
int h,w,y,x;
h = 10;
w = 25;
y = 15;
x = 20;
WINDOW * win = newwin(h ,w, y, x);
box(win,0,0);
wrefresh(win);
printw("Hello");
wprintw(win,"hi");
wrefresh(win);
getch();
refresh();
endwin();
return 0;
}
Any help is greatly appreciated.
答案1
得分: 0
以下是翻译好的部分:
可能问题出在窗口的位置(y 和 x 坐标)。设置 y=0
和 x=0
来将窗口定位在屏幕的左上角,然后查看是否显示出来。
你还可以通过在 main
函数的开头添加以下代码来检查 ncurses 是否正确初始化,以确保 ncurses 已成功初始化:
if (!initscr()) {
endwin();
return 1;
}
更新后的代码如下:
#include <iostream>
#include <ncurses.h>
int main() {
if (!initscr()) {
endwin();
return 1;
}
int h = 10, w = 25, y = 0, x = 0;
WINDOW *win = newwin(h, w, y, x);
box(win, 0, 0);
wrefresh(win);
printw("Hello");
wprintw(win, "hi");
wrefresh(win);
getch();
refresh();
endwin();
return 0;
}
希望对你有所帮助。
英文:
It's possible that the problem is with the window's position (y and x coordinates). Set y=0
and x=0
to position the window in the upper-left corner of the screen and see if it appears.
You can also check if ncurses is properly initialised by adding if (!initscr()) endwin(); return 1;}
at the beginning of the main
function to ensure that ncurses has been successfully initialised.
The updated code is as follows:
#include <iostream>
#include <ncurses.h>
int main() {
if (!initscr()) {
endwin();
return 1;
}
int h = 10, w = 25, y = 0, x = 0;
WINDOW *win = newwin(h, w, y, x);
box(win, 0, 0);
wrefresh(win);
printw("Hello");
wprintw(win, "hi");
wrefresh(win);
getch();
refresh();
endwin();
return 0;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论