Clear screen in C and C++ on UNIX-based system?

前端 未结 10 1587
青春惊慌失措
青春惊慌失措 2020-12-08 08:23

I want to know: how to clean screen on an UNIX-based system? I searched on the Internet, but I\'ve just found how to do it on Windows: system(\"CLS\") I don\'t want exactly

10条回答
  •  独厮守ぢ
    2020-12-08 09:11

    You can achieve this using CSI sequences:

    #include 
    int main()
    {
        printf("\x1b[H\x1b[J");
    }
    

    What does \x1b[H?

    Actually it is the same as \x1b[1;1;H, it means that it will move the cursor to row 1 and column 1.

    What does \x1b[J a.k.a \x1b[0;J?

    If n is 0 or missing, it will clear from cursor to end of screen.

    Source: https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences

提交回复
热议问题