windows console question

Hey guys how do you clear the screen in the windows console?? I thought it was

system("clear");

and it doesn't seem to work... Thanks!

AeonFlux1212
closed account (jwkNwA7f)
It is actually system("cls");
it's working thanks a lot !! :-)

AeonFlux1212
closed account (jwkNwA7f)
No problem
closed account (G309216C)
Using system() is not a great idea nor a good programming habit. Therefore I suggest you give this a look as a alternate to of system():
http://www.cplusplus.com/articles/4z18T05o/

A Proof-Of-Concept code demonstrating a alternate to system():
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
39
40
41
42
43
44
45
46
47
48
49
#include<Windows.h>
#include<iostream>

void ClearScreen(void)
  {
  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 );
  }

int main()
{
	std::cout<<"Hello World!\n Now can you clear me up? Press [ENTER] to continue";
	std::cin.get();
	ClearScreen();
	/*
	   Insert a break here to see that the screen is successfully cleared. 
	*/
}
closed account (jwkNwA7f)
Oh, I'm sorry I didn't mean to lead them in the wrong way.

I had been doing this myself and didn't know there was anything wrong with it.
@SpaceWorm

Thanks for the input, it's just that I'm not quite into windows.h ... could you tell me why

system("(...)");

is not recommended?
Topic archived. No new replies allowed.