Clearing output of a terminal program Linux C/C++

后端 未结 7 580
盖世英雄少女心
盖世英雄少女心 2020-11-27 14:29

I\'m interested in clearing the output of a C program produced with printf statements, multiple lines long.

My initial guess was to use

 printf(\"ou         


        
7条回答
  •  醉话见心
    2020-11-27 15:06

    Most terminals support ANSI escape codes. You can use a J (with parameter 2) to clear the screen and an H (with parameters 1,1) to reset the cursor to the top-left:

    printf("\033[2J\033[1;1H");
    

    Alternatively, a more portable solution would be to use a library such as ncurses, which abstracts away the terminal-specific details.

提交回复
热议问题