Clear screen

Hello there, is there another way to clear the console screen other then system("cls"); or printing 50 lines?


I would like to know because I don`t know why but system("cls") makes my mouse flash and the 50 line isn`t professional looking.
Thank you
There's an article on it here:
http://www.cplusplus.com/articles/4z18T05o/
Guys I have read your links but still don`t know which one to use.

system("CLS"); is a resource hog
printing 50 to 100 lines, its no good

I have
Curses, which I don`t really wanna go to and I have
<conio.h> which it says is that it dosn`t behave right.

Which one would you prefer or recommend?
Then by process of elimination, your last option is (copy/pasted from link above):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <windows.h>

void ClearScreen()
  {
  HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  /* Get the number of cells in the current buffer */
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;

  /* Fill the entire buffer with spaces */
  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Fill the entire buffer with the current colors and attributes */
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

  /* Move the cursor home */
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }

In reality, I'd say that the best way is to simply not clear the screen at all (if that's at all practical).

What do you need to clear the screen for?
In reality, I'd say that the best way is to simply not clear the screen at all (if that's at all practical).


What do you need to clear the screen for?

Yea I`m going to stop clearing the screen, its for a Tic Tac Toe game.
Thanks
Last edited on
Topic archived. No new replies allowed.