C++ Sleep Function (works on non Windows! Linux and Unix Compatible!)

Posted Jul 17, 2009 by zwrites / comments 0 comments / Print / Font Size Decrease font size Increase font size

IN this article I will give you a piece of code that will allow you to make your C++ programs sleep, even if you are not using Windows and therefore cannot include windows.h!

This article is part of a series of my articles containing snippets of C++ code that will perform various functions. Feel free to use them or modify them as needed, AS LONG AS YOU DO NOT RE-PUBLISH THEM.  Wheter you need an inspiration for a project, a way around a coding problem, or you are just curious feel free to check out the table of contents to my series right here.

void sleep(unsigned int mseconds) { clock_t goal = mseconds + clock(); while (goal > clock()); }

/* Nesecary includes:

Code  */

void sleep(unsigned int miliseconds)

{

clock_t goal = miliseconds + clock();

while (goal > clock());

}

//End of Code

z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z Liked What You Saw? z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z Theres More Where z z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z That Came From Here  z z z z z z z z z z z z z z z z z z z
z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z z

Rate this Article:

Be the first to rate me.

Image by laffy4k via Flickr

* You must be logged in order to leave comments, please login or join us.

Comments

No comments yet.



Bookmark and Share
Sign up for our email newsletter
Name:
Email: