home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

C++ pause?

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1563
Discussions: 200,985, Posts: 2,379,852, Members: 246,349
Old November 21st, 2004, 02:26 PM   Digg it!   #1 (permalink)
Member
 
NodX5's Avatar
 
Join Date: Nov 2004
Posts: 118
C++ pause?

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
NodX5 is offline   Reply With Quote
Old 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
agallers is offline   Reply With Quote
Old 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
agallers is offline   Reply With Quote
Old December 19th, 2004, 09:25 PM     #4 (permalink)
Senior Member
 
kantlivelong's Avatar
 
Join Date: Jul 2003
Location: NY
Posts: 771
Send a message via AIM to kantlivelong Send a message via Yahoo to kantlivelong
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
kantlivelong is offline   Reply With Quote
Old December 19th, 2004, 10:40 PM     #5 (permalink)
Senior Member
 
James T's Avatar
 
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.
James T is offline   Reply With Quote
Old December 19th, 2004, 11:12 PM     #6 (permalink)
Senior Member
 
kantlivelong's Avatar
 
Join Date: Jul 2003
Location: NY
Posts: 771
Send a message via AIM to kantlivelong Send a message via Yahoo to kantlivelong
Quote:
Originally Posted by James T
kantlivelong, good joke.

yep need teh humor
kantlivelong is offline   Reply With Quote
Old December 19th, 2004, 11:15 PM     #7 (permalink)
Member
 
NodX5's Avatar
 
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....
NodX5 is offline   Reply With Quote
Old 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
agallers is offline   Reply With Quote
Old December 21st, 2004, 01:30 AM     #9 (permalink)
I am a banana!
 
originel's Avatar
 
Join Date: Jun 2002
Location: Texas Tech
Posts: 3,921
Send a message via AIM to originel
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.
originel is offline   Reply With Quote
Old December 21st, 2004, 05:20 PM     #10 (permalink)
Member
 
NodX5's Avatar
 
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?
NodX5 is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Heads Up, Oh Minister of Avatars! Knothead IMO Community 5845 November 20th, 2009 02:48 PM
Is it really dual channel? alphaserpentis Mobile Computing 10 March 20th, 2004 02:52 AM
DOS question DoctorReno Applications and Operating Systems 16 July 19th, 2003 03:21 PM
ATA133 - How can you tell? Brangwen Storage Related 13 November 17th, 2002 03:05 PM
Can I Slow Down My Boot Speed? cracked Motherboards 11 March 5th, 2002 12:38 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3063)
Charges against non-tippers dropped.. (20)
Health Care Rationing (11)
Delete an OS (16)
Nvidia GTX 260 problem (9)
Laptop with wireless problem. (12)
windows vista security holes (19)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
Point and Shoot Camera Suggestions. (7)
windows 7 problem (7)
Internet Lost (5)
[F@H SPAM 11/16/09] ! 1/2 months to.. (39)
Recent Discussions
[F@H SPAM 11/16/09] ! 1/2 months to r.. (39)
Share an Easy Way to Convert DVD and .. (0)
windows vista security holes (19)
updating BIOS via winflash, claims fi.. (1)
New Server Configuration Suggestions (0)
Desktop Calendar Application (0)
cheap gaming laptop? (12)
Unallocated Space (2)
help me pls laptop just stopped worki.. (1)
C# + LINQ Help (7)
Nvidia GTX 260 problem (9)
Dynex DX E-402 (3)
EVGA 9800 gtx help with finding a goo.. (12)
Multiple Restarts Required at Boot (5)
Point and Shoot Camera Suggestions. (7)
Delete an OS (16)
cell phone won't work (0)
Is the PSU I received dead? (15)
Can't open Word (12)
Steam ID's, Gamertags etc... (4)
Games, Cables, PCI cards, and more fo.. (6)
Dept. of HS: NSA 'Helped' Develop Vis.. (17)
Linksys WMP54GS wireless card problem.. (5)
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)


All times are GMT -4. The time now is 03:34 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28