且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 C++ 在 Windows 和 Linux 中清除控制台

更新时间:2023-11-12 17:52:34

简答:你不能.

更长的答案:使用 curses 库(Unix 上的 ncurses,Windows 上的 pdcurses).NCurses 应该可以通过您的包管理器获得,并且 ncurses 和 pdcurses 具有完全相同的界面(pdcurses 也可以独立于控制台创建窗口,其行为类似于控制台窗口).

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).

最难的答案:使用 #ifdef _WIN32 之类的东西让你的代码在不同的操作系统上表现不同.

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