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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing the output screen

Status
Not open for further replies.

Jeeembo

Programmer
Jan 19, 2003
3
CA
I'm an amateur c++ programer using Metrowerks CodeWarrior. I currently have a for loop that outputs text using cout. The next time the loop is called, it creates another line of text in addition to the first line. I would like the for loop to clear the output screen each time it is called so only one line is being output at a time.
 
*************************************************************************
here is an example on how you might do it:
Code:
#include<iostream>
#include<cstring>
#include<ctime>
using std::cout;
using std::flush;
void sleep( clock_t wait );
#define CLEAR_SCREEN system(&quot;cls&quot;);
#define WAIT(x) sleep((long)(x));
#define SECOND 1000



void main()
{
	for(;;)
	{
		cout << &quot;Hello world !&quot;<<flush;// print some text
		WAIT(1.5 * SECOND); // waits before clearing the screen
		CLEAR_SCREEN; //now clear the screen
		WAIT(1 * SECOND); 
	}
}

void sleep( clock_t wait ) 
{
   clock_t goal;
   goal = wait + clock();
   while( goal > clock() )
      ;
}
[code]
 
i did a search and found the following solution which seems alot simpler. I do like the time thing though, thanks for the reply!

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

using namespace std;

int main ()
{
for(;;)
{
cout << &quot;Hello world !&quot; <<endl;
system(&quot;cls&quot;);
}
}

 
Would you have any time to read the lines that are printed on the screen ?
 
There is a built in &quot;pause&quot; function. It's called sleep.

Sleep(miliseconds)

so just do

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

Part and Inventory Search

Sponsor

Back
Top