There is an answer about system()
usage. And there is no standard C++ way to clear console window. For Windows platform you can use such code:
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);
}
And for linux, never tried, but found the way:
#include <curses.h>
erase();
system
, notSystem
, andclrscr
isn't a standard function. There is no standard way to clear it, but I'll bet it's not the IDE thatclrscr
doesn't work with. – Mariquillasystem
(lower-case letters). And thecls
command is operating-system specific (does not exist on Linux), and could have been removed or renamed by the sysadmin... – Decibelsystem
is a call that accepts any kind of unauthenticated shellcode, and it invokes a command interpreter that you usually do not want. Insofar it's extra overhead for adding a possible security exploit to your program. – Princessprincetonsystem
in general. The situation forsystem
is much the same as for using the arguments ofmain
: it's system dependent, so you'd better know what you're doing, but it would be silly to avoid it in general. – Discard