0
C++ Sleep Command of Sorts?
Does the built in compiler offer some sort of command that allows us to easily pause the code? My implementation is pausing before displaying the next line of text. I noticed it does not let you incrementally input for "cin" but rather collects all data at once, so it would make sense if there was not a wait command. Nevertheless, it would be extremely useful if this does have it. Thanks in advance!
4 Antworten
+ 7
Thanks @Ace!
Going to have to try using threads soon.
Outside of sl that is.
+ 4
I believe sleep() is not part of C++ std library, windows(windows.h) uses its own libraries to add the function.
+ 2
I have used this to pause the output on android.
int msleep(unsigned long milisec) {
struct timespec req={0};
time_t sec=(int)(milisec/1000);
milisec=milisec-(sec*1000);
req.tv_sec=sec;
req.tv_nsec=milisec*1000000L;
while(nanosleep(&req,&req)==-1)
continue;
return 1;
}
int main () {
// Code goes here.
unsigned int i = 0;
unsigned int t;
int sleep = 500;
t = v.size ();
while(i < t) {
/* The buffer must be flushed before each pause*/
std::cout << v[i] << std::flush;
msleep(sleep);
i++;
}
}