2015-07-10 17 views
0

好的,所以我正在嘗試使用NCurses庫C++更改終端背景。無法使用NCurses更改終端背景

這裏是我的代碼:

int ncurses_test() 
{ 
    initscr(); 
    start_color(); 
    init_pair(1, COLOR_GREEN, COLOR_BLACK); 
    init_pair(2, COLOR_GREEN, COLOR_BLACK); 
    init_pair(3,COLOR_BLUE, COLOR_RED); 
    wbkgd(WINDOW,COLOR_PAIR(3)) 
    noecho(); 
    raw(); 
    int c; 
    attron(COLOR_PAIR(1)); 
    printw("Write something [ESC to escape]: "); 
    while((c=getch())!=27) 
    { 
      move(10,0); 
      attron(COLOR_PAIR(1)); 
      printw("Keycode: %d, and the chracter: %c",c,c); 
      move(0,0); 
      attron(COLOR_PAIR(1)); 
      printw("Write something [ESC to escape]: "); 
      refresh(); 

    } 
    endwin(); 
    return 0; 
} 

編譯文件時,我得到一個錯誤。這裏是錯誤:

main.cpp: In function 'int ncurses_test()': 
main.cpp:27:18: error: expected primary-expression before ',' token 
     wbkgd(WINDOW,COLOR_PAIR(3)) 

有沒有人有任何想法?

回答

0

好吧,我設法讓我的代碼工作:

int ncurses_test() 
{ 
    initscr(); 
    start_color(); 
    init_pair(1, COLOR_GREEN, COLOR_BLACK); 
    init_pair(2, COLOR_GREEN, COLOR_BLACK); 
    init_pair(3, COLOR_BLACK, COLOR_BLUE); 
    init_pair(4, COLOR_BLACK, COLOR_WHITE); 
    noecho(); 
    WINDOW *win = newwin(10, 10, 10, 10); 
    wbkgd(stdscr, COLOR_PAIR(3)); 
    wbkgd(win, COLOR_PAIR(4)); 
    refresh(); 
    wrefresh(win); 
    raw(); 
    int c; 
    attron(COLOR_PAIR(1)); 
    printw("Write something [ESC to escape]: "); 
    while((c=getch())!=27) 
    { 
      move(10,0); 
      attron(COLOR_PAIR(1)); 
      printw("Keycode: %d, and the chracter: %c",c,c); 
      move(0,0); 
      attron(COLOR_PAIR(1)); 
      printw("Write something [ESC to escape]: "); 
      refresh(); 

    } 
    endwin(); 
    return 0; 
} 
+1

更好的後續本來要注意缺少分號。 –

+0

我是多麼愚蠢我感謝您發現。 – NSPredator