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

前端 未结 12 1526
我寻月下人不归
我寻月下人不归 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:37

    Short answer: you can't.

    Longer answer: Use a curses library (ncurses on Unix, pdcurses on Windows). NCurses should be available through your package manager, and both ncurses and pdcurses have the exact same interface (pdcurses can also create windows independently from the console that behave like console windows).

    Most difficult answer: Use #ifdef _WIN32 and stuff like that to make your code act differently on different operating systems.

提交回复
热议问题