tags:

views:

231

answers:

3

What is the method to tell the console to wait for x seconds. Is there a built in method or must I make one.

+6  A: 

It's platform specific. On Linux/UNIX, or other POSIX-compliant operating systems, you can use the sleep function, which takes a parameter in seconds. On Windows you can use Sleep, which takes a parameter in milliseconds.

Charles Salvia
I get the error, 'sleep': identifier not found
Mohit Deshpande
Maybe you should include: #include <windows.h>
Erkan Haspulat
See the links to the man pages for each sleep function. You probably need to include the appropriate headers. On Linux, that would be `unistd.h`, on Windows you want `Windows.h` I think. Also, please specify the OS you are using in the future, as it makes it easier for people to answer your questions succinctly.
Charles Salvia
+2  A: 

You are looking for the sleep method.

sleep(5);
Erkan Haspulat
As noted above, the sleep function is not a standard part of C++.
ChrisInEdmonton
+2  A: 

If you want it to be portable, you have to use preprocessing to determine what operating system it is and include the header as appropriate.

It would be good to make a function for calling sleep, like:

void portableSleep(int sec) {
#   ifdef POSIX
        sleep(sec);
#   endif
#   ifdef WINDOWS
        Sleep(sec * 1000);
#   endif
}

Autoconf can help you with this.

mathepic