Say i want to make a "loading..." appear for 5 seconds, then change to something else. How would i achieve that? Thanks
Say i want to make a "loading..." appear for 5 seconds, then change to something else. How would i achieve that? Thanks
I AM WINNER!!!1!111oneoneomne
That'll only work under Windows. The header will vary depending on your OS, but the function name and general idea will be very similar.Code:#include <windows.h> ... Sleep(5000) // Pause 5,000 milliseconds
For a somehwhat kludgy, yet standard way, look at the functions in the <ctime> header. They allow you to get the current time. So, if you record the starting time, then enter an infinite loop until the desired time difference is reached (by successively checking the time, perhaps not every loop iteration, though), then break out of the loop. Not terribly accurate or nice, but it should work.
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Or for posix,
#include <unistd.h>
unsigned int sleep(unsigned int period);
Note that it is in seconds.
Or, for conformance to UNIX 98,
#include <unistd.h>
int usleep(useconds_t period);
That's in microseconds.
this is the way I would do it, but that eats up your CPU cycles like you wouldn't believe... but then again it makes it look like your program is actually doing something for those 5 seconds and not just wasting everybody's time...Originally Posted by Zach L.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
[offtopic]
Did anyone else see the subject of the OP and giggle uncontrollably?
[/offtopic]Code:#include <ctimectrl> int main() { jump_ahead("5:00"); return 0; }
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
I was thinking more along the lines of:Originally Posted by pianorain
Code:#include <iostream> using std::cout; int main() { cout << "The Time Machine\n"; cout << "By H.G. Wells\n\n"; cout << "Chapter 1\n\n"; cout << "The Time Traveller (for so it will be convenient to speak of him) "; cout << "was expounding a recondite matter to us. His grey eyes shone "; cout << "and twinkeled, and his usually pale face was flushed and animated."; etc... }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
I was just asking myself, "How do u control time in c++? Forget C++. How do you control time in reality?"Did anyone else see the subject of the OP and giggle uncontrollably?
time control wasn't part of the C standard. The timecntrl header wasn't implemented until the C142 standard came out, so it's only <timecntrl>Originally Posted by pianorain
don't forget that it's implementation-specific, so you don't want to get that stuck in an infinite loop...
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
RIGHT !!!but that eats up your CPU cycles like you wouldn't believe...
This is an interesting case where it’s better to go with the non-standard code! Sleep(), etc., will release your CPU to do other stuff. Like major_small said, using the ISO/ANSI time functions will hog the CPU for the sole purpose of wasting time! This is BAD thing to do with a multitasking system.
If possible, it’s better check if “loading” is actually complete than, to use a fixed 5-second delay. For example, you could use Sleep() in a loop and check it every half-second or so.
BTW- I have a BASIC function: DelayDot(Delay, Count) that displays “Wait.......” Count is the number of “dots”, and Delay is the time between “dots”. I’ve used it kinda-like a library function in several BASIC programs.
d00der... in this case it's not bad... if you want to make it look like your program's doing something, this is a good thing... and it's not the functions that are doing it, it's your semi-infinite loop that's eating the cycles... find a way to slow the loop and you've got a way to lower the amount of CPU cycles you're using up...Originally Posted by DougDbug
Sleep() actually puts your program's thread into a sleep mode, where it can't do anything... but using the method I said, you can have your program "do that for 5 minutes"...
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
The Boost.Thread library provides a sleep function that works on multiple platforms.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
You can update a progress bar several times a second if you wish. You don't need to use-up all of the CPU cycles to do this.if you want to make it look like your program's doing something, this is a good thing...
Ummm... like Sleep() ?find a way to slow the loop and you've got a way to lower the amount of CPU cycles you're using up...
OK, it's not such a terrible thing for a user-mode program to waste a few (or a few billion) cycles for 5 seconds once in a while. The operating system will interrupt the time-wasting loop as it allocates time to other applications & processes. And, most of the time there's nothing else for the processor to do anyway. It's just one of those "what if everybody did it?" situations... If you were running several applications, and they are all running lots of tight "do-nothing" loops, you'd notice it.
>>If you were running several applications, and they are all running lots of tight "do-nothing" loops, you'd notice it.
I notice it when I have an un-Sleep(1)'ed PeekMessage() loop running, and I'm trying to compile a second program that's supposed to interact with it i.e. the second program takes about 20 times as long to compile, everything else on the computer slows to a standstill including switching apps etc..
Moral of the story: Don't deadsleep your programs for extended periods of time
Just Google It. √
(\ /)
( . .)
c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.