Is there a way in C++ to delay the program (for example before it displays something or calls a function) by a certain amount of seconds? I know it it possible in JavaScript, but is it in C++? Thank you.
Delaying the program
Collapse
X
-
-
Originally posted by rpm27Is there a way in C++ to delay the program (for example before it displays something or calls a function) by a certain amount of seconds? I know it it possible in JavaScript, but is it in C++? Thank you.
Example:
[CODE=c]#include <stdlib.h>
#include <iostream.h>
main()
{
while(!kbhit())
{
cout<<"******** *";
delay(100);///////Notice that the value is in miliseconds
}
}[/CODE]Comment
-
Voltem’s proposed solution is horribly wrong. Shockingly, each line of code, except for the braces, is questionable. And it’s only 10 lines of code.
#include <stdlib.h> . Old style header. The new form is <cstdlib> . However, it isn’t necessary here.
#include <iostream.h> . Old style header. The new form is <iostream> .
main(). Won’t compile. Only two acceptable forms of main. The one without arguments is int main().
kbhit. conio.h function. However, conio.h is compiler dependent, and has no standardisation . No good.
delay(100). Another conio.h function. That’s right, it doesn’t exist in cstdlib. And by relying on conio.h, you rely on a specific compiler.
Again, the correct way to insert a “pause” is to make the respective thread “sleep”. This is OS dependent. Also, because desktop operating systems are not real time OS, the sleep value is a minimum rather than a precise pause.Comment
Comment