[main] [more portable]

On codesnippets

Clear the screen in C/C++

Unfortunatly neither the C nor the C++ standard define a way to clear the screen in their standard library. This means you will have to resort a platform specific library or external programs.

Win32 console application - Microsoft Visual C++

See http://support.microsoft.com/support/kb/articles/q99/2/61.asp.

Linux and other unices

With ncurses

First include the ncurses header

#include <curses.h>

Next make sure you initialize the library

int main(int argc, char** argv)
{
	initscr();
	...
}

And now you can clear the screen like this

{
	...
	clear();      /* fill the virtual screen with spaces */
	refresh();    /* copy the virtual screen to the physical terminal */
	move(0,0);    /* move the cursor the the upperleft hand corner */
	...
}

For more information

man ncurses

Through calling an external program

First include the appropriate header

#include <stdlib.h>

Now call the external clear program like this

{
	...
	system("clear");    /* execute the external clear program */
	...
}

More information about clear

man clear

and more about the system call to execute external programs

man system