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 function in C++?
10 Answers
And before someone posts the usual "please email me the conio.h file" request, can I point out that this ancient Borland header file only contained the declaration of the function. You would also need the supporting Borland library, which will not be compatible with any modern C++ compilation system.
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.. :)