xxxxxxxxxx
#include <Windows.h>
int main() {
//print stuff
system("cls"); // clear console
}
xxxxxxxxxx
#include<iostream>
#include<Windows.h>
using namespace std;
int main()
{
//code.
system("cls"); //clear console.
return 0;
}
xxxxxxxxxx
#ifdef __cplusplus__
#include <cstdlib>
#else
#include <stdlib.h>
#endif
if (system("CLS")) system("clear");
xxxxxxxxxx
/*
I don't that it is a good practice to use system commands (system("");) for
these specific tasks so I made a function for clearing the console screen in
C/C++ and it pretty much does the exact same functionality of the
system("cls"); but just without calling a system command. (It is for Windows)
you can copy this function to your C/C++ code so you can use this function to
clear the console screen but check that Windows.h library is included in your
code. Here is the code:
*/
void clrscr() {
DWORD Unused = 0;
CONSOLE_SCREEN_BUFFER_INFO csbi;
COORD zerozeroc = {0, 0};
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
DWORD Length = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacterW(GetStdHandle(STD_OUTPUT_HANDLE), ' ', Length, zerozeroc, &Unused);
FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE), csbi.wAttributes, Length, zerozeroc, &Unused);
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), zerozeroc);
}