sleep function

I get a fast loop, so its not sleeping for 1 second on each iteration.
What am i missing?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <string>


#ifdef WIN32
    #include <windows.h>
    void sleep(int ms){
        Sleep(ms);
    }
#else
    #include <unistd.h>
    void sleep(int ms){
        usleep(ms * 1000);
    }
#endif

int main(){
    int count = 0;
    while (true){
        std::cout << count << std::endl;
        sleep(1);
        count++;
    }
}


1
2
metulburr@ubuntu:~$ uname -a
Linux ubuntu 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:35:23 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux 
Last edited on
set the parameter for sleep in your main loop to a higher number than 1.
oh, haha, i thought it already converted it to milliseconds with the 1000 in the func definition

How would you put the sleep function in a class while still complying with preprocessor directives?
1
2
3
4
class Utilities{
    public:
        //sleep();
}
Last edited on
Topic archived. No new replies allowed.