Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP!! Universal clear the screen code for c++ & Unix

Status
Not open for further replies.

bronzeiii

Programmer
Nov 13, 2001
1
US
Hey people
can someone please help me out? My project is due tomorrow. I need a universal code so i can clear the screen in visual c++ and unix. Please let me know.

thank you all
Jason
 
I am not sure but I believe Windows has a #define somewhere. SOmething along the lines of

#ifdef WINDOWS
// command to clear screen in windows
#else
Clear(); // not sure if this is the unix command... been
// 2 years since i used a unix system for coding
#endif

matt
 
hey Mat,

I tried the ways you said. They didn't work. So, is there any other ways that will make sure to clean the screen in both UNIX and windows systems..
 
I think this is the way to go. Instead of #ifdef windows , if you put a -D _UNIX in your make file and check on that instead it should go. (Once again, please keep in mind I have not worked on unix in a while and dont remember exaclty how to define things in a make file. I think the underscore is ignored with the -D but check on that please)

Matt
 
It's late getting it to you but this will work too.

#include <iostream.h>
#include <stdlib.h>

int main()

{
cout << &quot;Text before the clear screen.&quot; << endl;
system(&quot;CLS&quot;);
cout << &quot;Text following the clear screen.&quot; << endl;
return 0;
}

 
In Windows we can use clear() of conio.h. But for UNIX there is no console headers. So it is better to use &quot;clear&quot; command of UNIX system using 'system' function of stdlib.h.
include the following line at header includes.
#include <stdlib.h>

and use the following line where you want to clear screen.
system(&quot;clear&quot;);
 
Any way to add logic for portability?

if //TEST FOR PLATFORM//
system(&quot;clear&quot;);

else
system(&quot;cls&quot;);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top