C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 12th, 2008, 07:34 AM
ashuaki's Avatar
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 57 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 10 sec
Reputation Power: 7
General - Wait(): better than system.pause()?

I wrote a short function to wait a specified number of seconds, perfect for showing short samples to my friends who aren't even aware of how to use the command line, so that a program like

Code:
#include <iostream.h>

int main() {

x = 5+5;

cout << x;

}


wouldn't close instantly upon completion.

The function is
Code:
void Pause(int);

// other code

void Pause(int time) {
	clock_t endwait;
  endwait = clock () + time * CLOCKS_PER_SEC ;
  while (clock() < endwait) {}
  
}

*NOTE: Requires time.h

so
Code:
Pause(5);


Would hold the program for 5 seconds.

Is this preferable to system.pause()?
Does system.pause() have faculties for specifying a default pause period?

Reply With Quote
  #2  
Old March 13th, 2008, 09:14 AM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 9
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
system("pause");
has the same effect as when you use pause on the command line or in a batch file; it waits until the user presses a key.

Also, note that while your program is waiting, it's "spinning" the cpu at 100%.
Just use Sleep();
At the very least, call Sleep(1) in the loop, such that it only checks each 1 ms, or do sleep(seconds*1000)


system.pause() sounds like a .net thing, of which I have no idea.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - Wait(): better than system.pause()?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap