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

前端 未结 10 1588
青春惊慌失措
青春惊慌失措 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 08:56

    You can use the following code which use termcap for clear screen. (don't forget to link with the library)

    #include 
    #include 
    #include 
    
    void clear_screen()
    {
    char buf[1024];
    char *str;
    
    tgetent(buf, getenv("TERM"));
    str = tgetstr("cl", NULL);
    fputs(str, stdout);
    } 
    

提交回复
热议问题