How do I clear the screen without using system("cls");?

Recommended Answers

All 3 Replies

[search]how to clear the screen[/search]

Well C++ cant really clear the screen. You would have to create a fillscreen program to essentially fill the screen with blank space to get rid of whatever is on your console screen. Here is a small program from http://cpp.enisoc.com that fills the screen with " " or whitespace. I don't think <windows.h> is standard though, but I am not sure. Hope this helps.

#include <windows.h>

void clrscr()
{
  HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  COORD coord = {0, 0};
  DWORD count;

  CONSOLE_SCREEN_BUFFER_INFO csbi;
  GetConsoleScreenBufferInfo(hStdOut, &csbi);

  FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);

  SetConsoleCursorPosition(hStdOut, coord);
}

int main()
{
  clrscr();
  return 0;
}

Thanks! :) Most Appreciated!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.