Clr Screen + Pausing

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Clr Screen + Pausing

Postby DeAdMeAt » Thu Oct 02, 2003 10:50 pm

Well, i got the clear screen code from that topic, but now (im making a win32 consol app) and like i wanna make a word "dance" accross the screen, but it executes everything so fast that all they would see is the last name and its position. How would i pause it so they have time to see it or somtin, heres my code so far, ( i dont know if im doing it right cuz when i endl the last word is still on the top line in the program):

Code: Select all
#include <iostream.h>
#include <cstdlib>
main()
{
   cout<<"Hi"<<endl;
   system("cls");
   cout<<" Hi"<<endl;
   system("cls");
   cout<<"  Hi"<<endl;
   system("cls");
   cout<<"   Hi"<<endl;
   return 0;
}
DeAdMeAt
 
Posts: 3
Joined: Thu Oct 02, 2003 10:34 pm

Postby Justin » Fri Oct 03, 2003 1:23 am

Use the sleep function after each system("cls");

sleep(1000); // Time in milliseconds (i believe, look it up)
User avatar
Justin
 
Posts: 158
Joined: Tue Sep 30, 2003 10:07 am
Location: CA

Your right

Postby Christopher » Fri Oct 03, 2003 6:14 am

Yes that is the way to do it. More help on the SLeep() fnction. 1000 milliseconds = 1 second. Just in case you didn't know already. I wish I could see these post faster I want to be the first person to help out a beginner.
Christopher
 

Postby DeAdMeAt » Fri Oct 03, 2003 8:06 am

is there a header file that i have to include to make it work? cuz i just tried it and it didnt work, then i tried putting time.h and that didnt work:

Code: Select all
#include <iostream.h>
#include <cstdlib>

main()
{
   cout<<"Hi"<<endl;
   system("cls");
   sleep(500);
   cout<<" Hi"<<endl;
   system("cls");
   sleep(500);
   cout<<"  Hi"<<endl;
   system("cls");
   sleep(500);
   cout<<"   Hi"<<endl;
   return 0;
}


Error: error C2065: 'sleep' : undeclared identifier

so im "guessing" that im missing a header file i need to include?
DeAdMeAt
 
Posts: 3
Joined: Thu Oct 02, 2003 10:34 pm

Postby twm » Fri Oct 03, 2003 9:25 am

>is there a header file that i have to include to make it work?
Yes. But since sleep is not ANSI defined, you don't know for sure where it is. Though by your use of "cls", I'll assume you're on a Windows box:
Code: Select all
#include <windows.h>
#include <iostream>
#include <cstdlib>

using namespace std;

int main ( ) {
  cout<<"Waiting"<<flush;
  Sleep(200);
  cout<<"."<<flush;
  Sleep(200);
  cout<<"."<<flush;
  Sleep(200);
  cout<<"."<<flush;
  Sleep(200);
  cout<< endl <<"Done"<<endl;
}
The information given in this message is known to work on FreeBSD 4.8 STABLE.
*The above statement is false if I was too lazy to test it.*
If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
twm
 
Posts: 22
Joined: Mon Sep 29, 2003 2:38 pm

Postby HARiS_P » Fri Oct 03, 2003 9:38 am

also a thing you may not have noticed DeAdMeAt is that Sleep is with a capital S. It's really easy to forget to capitalize the S and might frustrate you quite a bit.
10 SIN
20 GOTO HELL

HPSoft
User avatar
HARiS_P
 
Posts: 226
Joined: Tue Sep 23, 2003 10:01 pm
Location: chicago, il

sleep

Postby teeyester » Fri Oct 03, 2003 10:40 am

twm
Trying to follow along here....been trying to get sleep to work for a while..including #windows.h does it on my compiler, but is there a reason why you flush the buffer on each side of the sleep function??
Just curious.......... :?:
teeyester
 

Postby Jimbo » Fri Oct 03, 2003 5:16 pm

i believe that cout << "something" does not automatically flush the stream. if thats true, you would have to flush it to make each "." appear before the call to Sleep(). there are some things that automatically flush the stream. cout << endl is one of them
User avatar
Jimbo
 
Posts: 601
Joined: Thu Sep 25, 2003 6:48 pm
Location: Seattle

Postby jgbauman » Sat Oct 04, 2003 2:27 am

...
#include <windows.h>
...
---
The information given in this message is known to work on FreeBSD 4.8 STABLE.

That was a nice one, Mr. Tab Window Manager ;-)
User avatar
jgbauman
 
Posts: 358
Joined: Sat Sep 27, 2003 9:00 am


Return to For Beginners

Who is online

Users browsing this forum: No registered users and 2 guests