January 21st, 2002, 01:54 AM
Clearing the screen on a linux system
I am writng a c++ program. In the program I want to clear the screen. How do I do that?
January 21st, 2002, 07:45 AM
What compiler are you using?
I am guessing this is a console application and not a windows application or you wouldn't be asking that question.
If you are using a Borland compiler you can include the conio.h header and use the function clrscr(). I am not sure which boreland compilers that support this function anymore. I know microsoft does not support this. I am not sure, but I don't believe *nix compilers do either.
January 21st, 2002, 02:32 PM
I'm sorry, I just realized you had Linux in your subject line.
In the case of clearing the screen in a linux app, I don't know of a standard function that does this. If someone else does, I would love to know also. The only method I know of is to print around 21 blank lines to the screen to accomplish this task.
I know there must be different ways to accomplish this though, especially if you are using ncurses.
January 22nd, 2002, 12:35 AM
I have found the answer
Thanks for your help. But I have found the way to clear the screen. You can use a function called system() in the <stdlib.h> library. If you are trying to clear the screen in dos you would use:
If you are trying to clear the screen in Linux/Unix you would use:
This function will also call the rest of the system calls.
January 22nd, 2002, 07:34 AM
I know of that, remember trying it once. I believe I ran into some sort of problem with it, just don't remember what.
Glad you found it.
January 22nd, 2002, 01:35 PM
Onslaught, I think the problem you might be referring to is the return value of the system() call (at least in DOS/Windows versions). The problem is that the system() call will always return 0, even if the program that was executed returns a different value. The *nix version of system() is much better because it returns the value from the program that was executed.
January 22nd, 2002, 02:12 PM
Actually, if I remember correctly, I can't say for sure, it has been years since I have actually tried to do it, but I believe that it was actually executing the command before I needed it to.