Helpful Information
 
 
Category: C Programming
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?


Thanks,
Jonathan Donaghe
http://www.functional-image.com

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.

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.

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:
system("cls")

If you are trying to clear the screen in Linux/Unix you would use:
system("clear")

This function will also call the rest of the system calls.


Thanks,
Jonathan Donaghe

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.

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.

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.










privacy (GDPR)