How do I clear the console in BOTH Windows and Linux using C++

前端 未结 12 1536
我寻月下人不归
我寻月下人不归 2020-11-30 01:54

I need a cross platform solution for clearing the console in both Linux and Windows written in C++. Are there any functions in doing this? Also make note that I don\'t want

12条回答
  •  孤街浪徒
    2020-11-30 02:39

    On linux it's possible to clear the console. The finest way is to write the following escape sequence to stdout:

    write(1,"\E[H\E[2J",7);
    

    which is what /usr/bin/clear does, without the overhead of creating another process.

提交回复
热议问题