C++ pause?  | | |
November 21st, 2004, 02:26 PM
|
#1 (permalink)
| | Member
Join Date: Nov 2004
Posts: 118
|
What is the line(s) for a temporary pause? ex. You have Hello! displayed on the screen then about 5 seconds later u say bye. And no I'm not looking for system("pause") or getchar() etc. i need like a temp. pause... if you can I'm not 100% sure if you can or not... but if you can I would like to know thanks for all who help
P.S. If you didn't read the thread title... in C++ (I use iostream.h for the #include line) and my compiler is.... Dev-C++ 4.9.9.0 |
| |
December 19th, 2004, 09:06 PM
|
#2 (permalink)
| | Junior Member
Join Date: Dec 2004
Posts: 3
|
There is none... Use the time.h library for windows or sys/time.h for UNIX |
| |
December 19th, 2004, 09:14 PM
|
#3 (permalink)
| | Junior Member
Join Date: Dec 2004
Posts: 3
|
This should work though:
#include <time.h>
float getElapsedTimeInMs()
{
//Return clock() as ms
//1 Second = 1000 milliseconds
return clock()/(CLOCKS_PER_SEC/1000);
}
void sleep(int ms)
{
float goal;
goal = ms + getElapsedTimeInMs();
//Do nothing until goal is greater than the
//current elapsed time
while( goal >= getElapsedTimeInMs())
;
}
i found it here: http://steinsoft.net/index.php?site=...ippets/Cpp/no4 |
| |
December 19th, 2004, 09:25 PM
|
#4 (permalink)
| | Senior Member
Join Date: Jul 2003 Location: NY
Posts: 771
|
another easy way is to do a quick for loop..
for(int i=0; i<100000000;i++)
__________________ RackByte.com - Web Hosting / Reseller Hosting / VPS / Dedicated Servers / Domain Registration
|
| |
December 19th, 2004, 10:40 PM
|
#5 (permalink)
| | Senior Member
Join Date: Jul 2004 Location: New Zealand
Posts: 582
|
Do not forget that the system must share cpu time. You should do a system call in this instance. kantlivelong, good joke. |
| |
December 19th, 2004, 11:12 PM
|
#6 (permalink)
| | Senior Member
Join Date: Jul 2003 Location: NY
Posts: 771
| Quote: |
Originally Posted by James T kantlivelong, good joke. | yep need teh humor  |
| |
December 19th, 2004, 11:15 PM
|
#7 (permalink)
| | Member
Join Date: Nov 2004
Posts: 118
|
hmm i tried that just to see how it'd work but i got this as an error while trying to compile it
[Linker error] undefined reference to `WinMain@16'
idk what thats suppose to mean.... |
| |
December 21st, 2004, 01:26 AM
|
#8 (permalink)
| | Junior Member
Join Date: Dec 2004
Posts: 3
|
I'm not sure what that error means - but I used that code in a program of mine and it worked fine. Did you remember to #include <time.h> in all the right files? Also - like James T said, if you're running other programs at the same time then this isn't the best idea... same goes for the for loop (except the for loop might take diff. amounts of time on diff computers). Good luck |
| |
December 21st, 2004, 01:30 AM
|
#9 (permalink)
| | I am a banana!
Join Date: Jun 2002 Location: Texas Tech
Posts: 3,921
|
wow...that reference is to windows code. Basically windows programs don't have a main function, but rather a winmain function. When you set up your project, did you make sure to set it for a console project? also are you using visual studio .net/.net 2003? i've found that these newer versions don't play too well with the standard library really. |
| |
December 21st, 2004, 05:20 PM
|
#10 (permalink)
| | Member
Join Date: Nov 2004
Posts: 118
|
nope for my compiler im using Dev-C++ some freeware program and I did this very late in the evening when i had nothing better to do and i copied straight from his code so yea... no other programs were running (except my os obviously) and the code was not altered one bit
could this be from my compiler? |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |