Well, I'm trying to find a way to make my program take brakes while executing. For example it outputs a number then waits 10 seconds and outputs a new number and keeps on doing this.
Is there a way to achieve this. I'd appreciate your help.
Well, I'm trying to find a way to make my program take brakes while executing. For example it outputs a number then waits 10 seconds and outputs a new number and keeps on doing this.
Is there a way to achieve this. I'd appreciate your help.
One method from the C++ faq on this website:
Code:#include <ctime> ... ... long delay = clock() + 10000; //10 secs x 1000 milliseconds/sec while( clock() < delay ) continue;
Last edited by 7stud; 06-06-2005 at 02:38 AM.
If you have <windows.h>
Then you should be able to do this
Code:#include<windows.h> #include<iostream> using namespace std; int main() { cout<<5<<endl; Sleep(2000);// in milliseconds, wait 2 second cout<<8; int pause; cin>>pause; }
I don't know if I have windows.h. How can I check that? I'll try both ways.
Last edited by cnoob; 06-06-2005 at 02:57 AM.
What OS/compiler are you using
Bloodshed
You're still neglecting most of sand_man's question. If you're using Dev-C++ under windows, you should have windows.h. Why don't you just try the code and check? If you don't have windows.h you're just going to get an error message.
you would have windows.h unless you manually deleted it, but since you dont even know you have it then i'm doubting it was deleted.
Registered Linux User #380033. Be counted: http://counter.li.org
cnoob,
Here are the basic tradeoffs:
7stud's solution is standard-portable C++. But, with a multitasking system it hogs CPU cycles while looping like crazy.
treenef's solution frees-up the CPU to do other stuff during your program's sleep time. But, is not standard or portable (It's Windows only).
It's OK to use non-standard code, but you should know that your code is non-standard, and you should have a good reason for using it.