I\'ve looked everywhere for this function and cannot find the header files to make this work. It says clrscr() undeclared which brings me to the question. Is clrscr(); a fun
The easiest way to clear the screen in real C++ is to just send out a bunch of blank lines. Of course this is assuming that stdout is directed at the screen and not a file:
for (int i = 0; i < 80; ++i)
cout << "\n";
cout << endl;
It used to be a function in <conio.h>, in old Borland C compilers.
It's not a C++ standard function.
As mentioned before, clrscr() is from turbo c++, inside conio.h
For all intents and purposes, conio.h is "non standard", and as such should be probably avoided.
I tend to use the precompiler to choose what to use for a simple clear screen, and just call the operating system's clear program.... it's smart enough to know how "tall" the screen is.
// somewhere in the program
#define WINDOWS 1
void console_clear_screen() {
#ifdef WINDOWS
system("cls");
#endif
#ifdef LINUX
system("clear");
#endif
}
In windows, you may want to look at the windows.h, You can interact with the windows console directly using a "handle", often noted in code as an hWin.
In linux, i've had good luck with curses/ncurses, although it is a little confusing at first.
update Calling system programs (clear.exe?)is a potential security risk - if someone is able to hijack the system call somehow thru an alternate avenue, they can force your program to do strange things. My recommendation is to dig into your platform's console api to get these things done.
you can use the system cls command to clear the output screen..
clrscr() is from turbo c++, inside conio.h and conio.h is "non standard", and as such should be probably avoided. example
#include<windows.h>
main()
{
some code....;
system("cls");
some more code;
}
its tested and works.. i use dev c++ with mingw compiler.. :)