Clear Screen using C++

后端 未结 4 1659
小蘑菇
小蘑菇 2020-12-08 05:27

I would like to clear the CMD screen I have seen a few options first is

system(\'clr\');  

but dont want to use system cause then it makes

4条回答
  •  悲哀的现实
    2020-12-08 06:14

    If you want a solution that will work on Windows, Mac & Linux/UNIX, you will need to come up with your own implementation. I do not believe that there is a single way to do it that works on all platforms.

    For Mac/Linux/UNIX/BSD/etc., ncurses provides an easy way to do this (http://www.gnu.org/software/ncurses/).

    For Windows, you will probably want to look into conio.h (http://en.wikipedia.org/wiki/Conio.h) or PDCurses (http://pdcurses.sourceforge.net/) or something similar. Alternatively, it would seem that you can do this without any third-party libraries, according to this Microsoft KB article: http://support.microsoft.com/kb/99261.

    There is unfortunately no standard C/C++ function to do this. You should be able to write a small function which will build & work on any platform using the different methods I mentioned and some preprocessor directives.

    If you don't have a convenient way to detect the platform, I would probably recommend cmake.

提交回复
热议问题