白衣染霜花
关于system()用法有一个答案。而且没有清除控制台窗口的标准C ++方法。对于Windows平台,您可以使用以下代码:void clear() { COORD startPos = { 0, 0 }; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO screen; DWORD written; GetConsoleScreenBufferInfo(hConsole, &screen); FillConsoleOutputCharacterA(hConsole, ' ', screen.dwSize.X * screen.dwSize.Y, startPos, &written); FillConsoleOutputAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE, screen.dwSize.X * screen.dwSize.Y, startPos, &written); SetConsoleCursorPosition(hConsole, startPos);}对于linux,从未尝试过,但是找到了方法:#include <curses.h>erase();