system("cls")

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2008
Posts: 21
Reputation: azwraith69 is an unknown quantity at this point 
Solved Threads: 0
azwraith69's Avatar
azwraith69 azwraith69 is offline Offline
Newbie Poster

system("cls")

 
0
  #1
Jan 31st, 2009
hello.. thx in advance

just want to ask something..

is there any portable functions that is equivalent to system("cls")?
a function that clears the screen? since system() is not portable..

thx...
I am living in a mere program...
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,661
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: system("cls")

 
0
  #2
Jan 31st, 2009
system() is portable -- the commands it execute are not. There are no portable ways to clear the screen. You might have to do something like this, where each compiler for the target os defines one of the symbols listed in the code below.
  1. #ifdef _UNIX_
  2. system("clear");
  3. #elif def _WINDOWS_
  4. system("cls");
  5. #elsif def _OTHER_OPERATING_SYSTEM
  6. systgem(<put here whatever works>);
  7. #endif
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,273
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 543
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: system("cls")

 
0
  #3
Jan 31st, 2009
no.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,953
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: system("cls")

 
0
  #4
Jan 31st, 2009
Why do you want to do that?
(In other words, unless you are writing a full-screen text application like an editor or video game, don't do that.)

Otherwise, on Windows, see Example Two

On Unix/Linux/POSIX:
  1. #include <unistd.h>
  2. #include <term.h>
  3.  
  4. void clearscreen()
  5. {
  6. if (!cur_term)
  7. {
  8. int success;
  9. setupterm( NULL, STDOUT_FILENO, &success );
  10. if (success <= 0) return;
  11. }
  12. putp( tigetstr( "clear" ) );
  13. }
You'll need to link with one of the following (depending on your system):
-lcurses
-lncurses
-lterminfo

If you are writing a CUI application, though, you should just use Curses directly:

PDCurses
Windows, DOS, OS/2, Plan 9, etc
http://pdcurses.sourceforge.net/

NCurses
POSIX systems, Mac OS X, etc
http://www.gnu.org/software/ncurses/

Getting started
http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/
http://web.cs.mun.ca/~rod/ncurses/ncurses.html

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 8
Reputation: hahanottelling is an unknown quantity at this point 
Solved Threads: 0
hahanottelling hahanottelling is offline Offline
Newbie Poster

Re: system("cls")

 
0
  #5
Feb 1st, 2009
Couldn't you just print a lot of newlines and then move the cursor to the top of the window?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,661
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1500
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: system("cls")

 
0
  #6
Feb 1st, 2009
You could, but that isn't portable either. And how many newlines would you print? How would you move the cursor?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1805 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC