beginner c++ question

widgetman

Registered
im very new at c++ and want to now if there is a way to run some sort of sleep() or wait() or something that will pause the code for a given amount of time.

im making terminal applications and i have experience with other languages that all have some similar command...so i was just wondering...

thanks
 
In your terminal, type in "man 3 sleep" without the quotes. That should give you information about a sleep function that provides the functionality you're asking for.
 
How about nanosleep? man nanosleep should give you all you need to know how to use it.
 
im getting some weird errors with nanosleep...like:
"invalid conversion from 'int' to 'timespec*' "
and
"invalid conversion from 'int' to 'const timespec*' "

the help file said it takes more than one parameter, but im not doing the parameters right...

my code is:
Code:
for (int i=0;i<=26;i++) {
     cout << "*";
     nanosleep(500, 500);
}
 
That's because it takes a timespec structure as an argument, and not integers. That's why pasing 500 won't work.

What you could try is do something like
Code:
struct timespec tp;
tp.tv_sec = 1; //seconds so sleep for
tp.tv_nsec = 1000; //nano seconds to sleep for
nanosleep(&tp, NULL);
 
Back
Top