Click to See Complete Forum and Search --> : Clear Screen
Ramandeep
Oct 16th, 2001, 04:46 PM
Is there a simple way to clear the CONSOLE screen under C++. In Pascal you use clrscr to clear the screen. How can I clear the screen under C++.
I will also be running the same program under the UNIX OS and don't want anything that is specific to the WINDOWS OS.
:) THANKS IN ADVANCE :)
filburt1
Oct 16th, 2001, 05:32 PM
If you have a Borland compiler (and abdul thinks this works under Borland too):
#include <conio.h>
clrscr();
HarryW
Oct 16th, 2001, 07:59 PM
That's a Borland thing. Borland consoles aren't the same as VC++ consoles, they have some extra stuff built into them.
As far as I know (I've read a lot of threads discussing this very topic) there is no platform-independant way to do it. If there is, I want to know :)
You can use the Shell() function to send a command to the command prompt, but the command to clear the console will be different on different systems. On Linux it's clear, on DOS it's cls.
In the case of Linux (well, all the bash prompts I've used anyway), the clear is just a lot of newlines - just enough to make the existing text scroll off the top of the screen. You can do a similar thing with DOS. The problem with this is:
- how many lines do you need to add? It may not be constant
- it's slow
If anyone knows how to do this in a OS-independant way, I'd be very interested.
KingDavid
Oct 16th, 2001, 08:56 PM
If trying to be fast there is no OS independent way to clear the screen. If you'r useing the console you'r probly not trying to be fast, so this should work on any OS.
void ClearScreen()
{
for(int c = 0; c < 1000; c++)
cout << endl;
}
if you want to clear the screen fast you have to get into the API of what ever operating system you're using. Like the FillConsoleOutputCharacter function in the windows API.
KingDavid
Oct 18th, 2001, 02:51 PM
Yes but you only wanted to clear the screen right.:D
I only know move the cursor using windows API:(
abdul
Oct 18th, 2001, 02:55 PM
Why not change some code (for clearing the screen) if you want it to run on Linux.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.