Universal OS screen clear?

Apr 11, 2012 at 11:13pm
Is there a universal OS screen clear function? To my understanding system("cls") is for windows, system("ls") can be used for Linux (please correct me if wrong) but I am using a Mac for programming and my professor uses windows, I would like to clear the screen at certain points to neaten things up. Any advice is appreciated.
Apr 11, 2012 at 11:47pm
hi gmenfan83

i'm afraid i do not have the answer to your question, but i wish to clarify about system("ls").

the command "ls" is used to list folders in the directory for linux. the right command to clear the screen is "clear".
Apr 11, 2012 at 11:52pm
I see, thanks, I know the ls-command from terminal on a Unix machine I just saw someone say it was able to be used Linux trying to clear the screen. I am strictly speaking in terms of c++ also, no terminal commands.
Last edited on Apr 11, 2012 at 11:53pm
Apr 12, 2012 at 12:07am
Nice attitude, gmenfan83, no shell/system commands. They aren't safe, and bla, bla, bla...
http://www.cplusplus.com/articles/4z18T05o/
Apr 12, 2012 at 12:09am
Thanks EssGeEich!
Apr 12, 2012 at 12:13am
Anyways, there is no 'single' clear screen functions, you can make your own with IFDEF's depending on the OS.
Apr 12, 2012 at 12:20am
Ah, I won't even worry about it I suppose. Its no biggie, I just like things to astetically look pleasing. Thanks for the tips though!
Last edited on Apr 12, 2012 at 12:21am
Apr 12, 2012 at 3:01am
Clearing the screen is a system-specific thing to do.

You really don't need to do it for homework stuff. If undaunted, though...

If you don't think that using system() will get you into trouble with your professor, use:

if (system( "cls" )) system( "clear" );

If your professor is using Windows, this will probably cause his virus scanner to pop up complaining that your program is doing something uncouth.

The actual, proper way to do this kind of thing is explained in the Clear the screen Article:
http://cplusplus.com/articles/4z18T05o/

This requires a little bit of extra work when compiling on POSIX systems though... (you will have to link with libcurses).

Good luck!
Apr 12, 2012 at 10:40am
Thank you Duoas!
Topic archived. No new replies allowed.