943,796 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5125
  • C++ RSS
Jan 31st, 2009
0

system("cls")

Expand Post »
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...
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
azwraith69 is offline Offline
21 posts
since Jul 2008
Jan 31st, 2009
0

Re: system("cls")

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.
C++ Syntax (Toggle Plain Text)
  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
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Jan 31st, 2009
0

Re: system("cls")

no.
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is online now Online
16,506 posts
since Apr 2005
Jan 31st, 2009
0

Re: system("cls")

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:
C++ Syntax (Toggle Plain Text)
  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.
Featured Poster
Reputation Points: 1140
Solved Threads: 229
Postaholic
Duoas is offline Offline
2,039 posts
since Oct 2007
Feb 1st, 2009
0

Re: system("cls")

Couldn't you just print a lot of newlines and then move the cursor to the top of the window?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hahanottelling is offline Offline
16 posts
since Jan 2009
Feb 1st, 2009
0

Re: system("cls")

You could, but that isn't portable either. And how many newlines would you print? How would you move the cursor?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: question on c++ programing
Next Thread in C++ Forum Timeline: Variable working incorrectly?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC