清除多行

use*_*204 5 c terminal console printf

例如,是否可以清除 C 中的多行并保留其他行。

代码:

Displaysenrsordata
  loop 
    printf("This info stays"); <-stay on screen
    printf("This info stays"); <-stay on screen
    printf("This info Refreshes"); <-update redraw
    printf("This info Refreshes"); <-update redraw
    printf("This info Refreshes"); <-update redraw
Run Code Online (Sandbox Code Playgroud)

本质上,我想让一些文本留在同一个地方,并在不清除整个屏幕的情况下重绘更新数据。

suj*_*jin 6

如果您在 linux 上工作,请使用ncurses

例子:

#include <stdio.h>
#include <ncurses.h>
  int main (void)
  {
    int a = 0;
    initscr ();
    printw("This info stays \n");
    printw("This info stays\n");
    curs_set (0);
    while (a < 100) {
            mvprintw (3, 4, "%d", a++);
            mvprintw (3, 8, "%d", a++);
            mvprintw (3, 12, "%d", a++);
            refresh ();
            sleep (1);
    }
    endwin();
    return 0;
 }
Run Code Online (Sandbox Code Playgroud)


Bab*_*yan -5

不,您不能仅清除控制台窗口的一部分。