AmitM9S6
AmitM9S6

Reputation: 131

Using a timer in C++

I've searched over the internet for a function that can "hold" my program..

I've seen the function sleep(), though it does not work for me, saying it is undeclared.. (I have included stdlib.h/time.h/iostream)

I do not have parrel stuff that are working in the side, so even if I stop the whole program, that's okay..

for example :

sleep(3000) cout << "Hello World";

Thanks!

Upvotes: 1

Views: 268

Answers (3)

Liam
Liam

Reputation: 1524

Try "Sleep" with a capital S..... and #include winbase.h

Upvotes: 1

LukeStoneHm
LukeStoneHm

Reputation: 122

try this.

usleep(microseconds) 

1000 microseconds in a millisecond

You may need to: #include <unistd.h>

Upvotes: 1

Tobias Hermann
Tobias Hermann

Reputation: 10926

If you are using c++11 you have a portable way to suspend your thread: http://en.cppreference.com/w/cpp/thread/sleep_for

otherwise you have to include Windows.h to use Sleep: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686298%28v=vs.85%29.aspx

Upvotes: 2

Related Questions