943,355 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 11592
  • C++ RSS
You are currently viewing page 1 of this multi-page discussion thread
Dec 24th, 2004
0

I Summon Clear Screen

Expand Post »
Sorry to be such a gimmy gimmy... but I couldn't find any threads on some code that clears the screen, just like DOS's 'CLS' and Bash's 'Clear'...I need a function that does the same thing as both CLS and Clear. Thanks for reading and or helping out.
Reputation Points: 12
Solved Threads: 6
Junior Poster
Geek-Master is offline Offline
156 posts
since Dec 2004
Dec 24th, 2004
0

Re: I Summon Clear Screen

Hmm.... 'clrscr()' from 'conio.h' should serve your purpose
Reputation Points: 10
Solved Threads: 0
Newbie Poster
jeanatkin is offline Offline
10 posts
since Dec 2004
Dec 24th, 2004
0

Re: I Summon Clear Screen

You don't want to do that. It's considered rude in command line programs and in all others building up your own screen will replace what's underneath it anyway (at least while your application is running).

There's no platform independent way to achieve it btw (probably because of that) so if you insist you'll have to plow through your compiler documentation to see if there's a function for it and how to call it.
You could of course always figure out the memory location of your screenbuffer and manually poke zeros into each position and hope.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 24th, 2004
0

Re: I Summon Clear Screen

>I need a function that does the same thing as both CLS and Clear.
C++ Syntax (Toggle Plain Text)
  1. #include <stdlib.h>
  2. #include "system.h"
  3.  
  4. void clear()
  5. {
  6. #if defined(DOS_BASE)
  7. system("CLS");
  8. #elif defined(UNIX_BASE)
  9. system("clear");
  10. #else
  11. #error Unsupported system
  12. #endif
  13. }
Will it work? Probably, provided you define either DOS_BASE or UNIX_BASE in system.h. Is it advisable? No, not really. But I've described why elsewhere, and it's really your decision.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Dec 25th, 2004
0

Re: I Summon Clear Screen

Just to be sure that we are on the same page... the function should only clear the 'output' on the screen... not do anything with the actual program or command prompt. I want to create 'animation' in the command prompt, I have done this before with Batch files by echoing text and then 'cls' and echoing the text in another spot on the line. I want to be able to do the same, by just clearing whats on there and then creating the illusion of animation.
Reputation Points: 12
Solved Threads: 6
Junior Poster
Geek-Master is offline Offline
156 posts
since Dec 2004
Dec 25th, 2004
0

Re: I Summon Clear Screen

Quote originally posted by Geek-Master ...
Just to be sure that we are on the same page... the function should only clear the 'output' on the screen... not do anything with the actual program or command prompt. I want to create 'animation' in the command prompt, I have done this before with Batch files by echoing text and then 'cls' and echoing the text in another spot on the line. I want to be able to do the same, by just clearing whats on there and then creating the illusion of animation.
I'm having trouble deciding if you're stupid or just can't read well. We understand exactly what you want. You've had three useful replies and two viable solutions. What need is there to be on the same page if you already have a workable answer?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Dec 25th, 2004
0

Re: I Summon Clear Screen

I'm just stupid, and lovin every minute of it
Reputation Points: 12
Solved Threads: 6
Junior Poster
Geek-Master is offline Offline
156 posts
since Dec 2004
Dec 25th, 2004
0

Re: I Summon Clear Screen

At least you can admit it. Kudos.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
Dec 25th, 2004
0

Re: I Summon Clear Screen

LOL, sorry to be such an 4$$ but I'm still a new guy in programming. Just trying to learn a lot at one time. Thanks for the replys.
Reputation Points: 12
Solved Threads: 6
Junior Poster
Geek-Master is offline Offline
156 posts
since Dec 2004
Dec 26th, 2004
0

Re: I Summon Clear Screen

if you want to clear selective positions, you'll need to write the text that's there in the background colour to those positions.

This is an age old technique employed by terminal applications on mainframes and it works well.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

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: Possible alternatives?
Next Thread in C++ Forum Timeline: Compile and linking problems with Microsoft Visual C++





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


Follow us on Twitter


© 2011 DaniWeb® LLC