Where in Visual Studio 2012 nanosleep() gone? What include i need to add to get the nanosleep(), or what is the best way to make a delay in miliseconds in C++ Visual Studio 2012?
Asked
Active
Viewed 3,528 times
2
-
Seems to me that `nanosleep` is POSIX. It's certainly not required for standard C or standard C++. – Pete Becker Apr 13 '13 at 15:32
-
Since `nanosleep` is a POSIX function, I'd guess that it's not "gone", as it was never actually there. – Daniel Kamil Kozar Apr 13 '13 at 15:32
1 Answers
3
You could try this, which is portable, Standard C++11 code:
#include <thread>
#include <chrono>
// ...
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
Alternatively, you could use the Windows API Sleep()
(declared in the WinBase.h
Windows header):
::Sleep(1000);

AJM
- 1,317
- 2
- 15
- 30

Andy Prowl
- 124,023
- 23
- 387
- 451