123456789101112131415
void ClrScrn(char attrib) { COORD pos = { 0, 0 }; DWORD written; unsigned size_; size_ = line_max * column_max; FillConsoleOutputCharacter(console, ' ', size_, pos, &written); cout << written; //FillConsoleOutputAttribute(console, attrib, size_, pos, &written); //SetConsoleCursorPosition(console, pos); }
12345678910111213141516171819202122
#include <iostream> using namespace std; #include <windows.h> #include <conio.h> void _clrscr() { HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE); DWORD Written; COORD Home; Home.X=0; Home.Y=0; FillConsoleOutputCharacterA(hOut,' ',80*300,Home,&Written); SetConsoleCursorPosition(hOut,Home); } int main() { cout<<"Hello World !"<<endl; cout<<"Press any key to clear the screen"; _getch(); _clrscr(); return 0; }
HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);