| | |
Using time in programs
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2004
Posts: 15
Reputation:
Solved Threads: 0
I asked before for a time delay function which is like system ("pause") but depend on time instead of keys , to elaborate i want the program instead if writing " press any key to contiue " i want it to freeze for example for 2 or 3 sec then continue. i got replies which i cant understand, its just codes without explaining the meaning of the function or the input or the output. plz reply me again with more explanation . i really need that facility and i want to understand it.
"NOTE: i am using simple console app with visiual C++ 6 compiler"
thnx
hope u can reply me soon
bye
"NOTE: i am using simple console app with visiual C++ 6 compiler"
thnx
hope u can reply me soon
bye
•
•
Join Date: Mar 2004
Posts: 28
Reputation:
Solved Threads: 0
yea... it's very useful... here's the code:
#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;
if you do not have the windows.h header for some odd reason unknown to me, which you have VC++6 so you should, try to run a loop a bunch of times through to give it that effect which windows.h basically does. it just measures your processor speed and does an equation using that... peace...
#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;
C++ Syntax (Toggle Plain Text)
int main() { cout << "Hello..."; Sleep(2000); cout << "World..."; cin.get(); return 0; }//end main function
if you do not have the windows.h header for some odd reason unknown to me, which you have VC++6 so you should, try to run a loop a bunch of times through to give it that effect which windows.h basically does. it just measures your processor speed and does an equation using that... peace...
Hey not sleep(2000) bleek, sleep(4) might be a nice number if sleep() is the same for your complier as for mine.I use Borland C++ and sleep() counts in seconds.
There is also delay(int) funtion.It counts in some unit lower than a second.
#include <stdlib.h>
#include <dos.h>
(I dont know which compiler you guys use)
:surprised
There is also delay(int) funtion.It counts in some unit lower than a second.
#include <stdlib.h>
#include <dos.h>
(I dont know which compiler you guys use)
:surprised
•
•
Join Date: May 2004
Posts: 15
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Bleek
yea... it's very useful... here's the code:
#include <iostream>
#include <windows.h>
#include <cstdlib>
using namespace std;
C++ Syntax (Toggle Plain Text)
int main() { cout << "Hello..."; Sleep(2000); cout << "World..."; cin.get(); return 0; }//end main function
if you do not have the windows.h header for some odd reason unknown to me, which you have VC++6 so you should, try to run a loop a bunch of times through to give it that effect which windows.h basically does. it just measures your processor speed and does an equation using that... peace...
but can u explain more plz .
when i use this code is makes the whole word "hello world" appears after 5 sec apox. i want appear to appear then after 5 sec world continue.
plz explain what is 2000 .
and some1 told me that this function have bad effects on the pc "This is a reply u can see it if u searched after before that post by few ones"
so plz tell me that stuff
and really thnx
bye
•
•
Join Date: Jun 2004
Posts: 4
Reputation:
Solved Threads: 0
i have a good one from my book. 
#include <iostream.h>
#include <time.h> // my compiler is out dated
update as needed
int main()
{
cout << "enter delay time, in seconds : ";
float secs;
cin >> secs;
clock_t delay = secs * CLOCKS_PER_SEC ;
cout << "starting\a\n";
clock_t start = clock();
while (clock() - start < delay );
cout << "done \a\n";
return 0;
}

#include <iostream.h>
#include <time.h> // my compiler is out dated
update as neededint main()
{
cout << "enter delay time, in seconds : ";
float secs;
cin >> secs;
clock_t delay = secs * CLOCKS_PER_SEC ;
cout << "starting\a\n";
clock_t start = clock();
while (clock() - start < delay );
cout << "done \a\n";
return 0;
}
![]() |
Similar Threads
- Too much memory being consumed! Also is it time to fsck my HD? (*nix Hardware Configuration)
- Timing programs in C (C)
- remove programs from right-click (IT Professionals' Lounge)
- Programs at Windows startup (Community Introductions)
- Reformat or use Imaging backup? (Windows tips 'n' tweaks)
Other Threads in the C++ Forum
- Previous Thread: NOOB question , graphical tiles
- Next Thread: regarding round robin algorithm
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news node number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector visualstudio win32 windows winsock word wordfrequency wxwidgets





