C++ Question (Yet another!)

What I need to do is pause the screen numerous times. An array will be displayed, paused for x number of seconds and then the next array will be displayed. I know I can use a system(“pause”) in between each but I don’t really want to make the user hit a key in between every array. Is there a way to set it up so that there is a pause x seconds long in between each array? Thanks in advance!

All my C books are upstairs… man sez there’s a sleep() function in <unistd.h>.


SYNOPSIS
       #include <unistd.h>

       unsigned int sleep(unsigned int seconds);

DESCRIPTION
       sleep()  makes the current process sleep until seconds seconds have elapsed or a signal
       arrives which is not ignored.


A quick scan of my C++ reference (no C++ programmer should be without one) says that the “sleep” function will do the trick:

Giving a sleep(5); in your program would hold things for milliseconds.

How’s the class coming?

Try the function “sleep”. It’s defined in different header files, depending upon exactly which C++ compiler you’re using. If it’s POSIX compliant, it’s defined in unistd.h. The argument is the number of seconds to sleep, and the return value is zero if all the time has elapsed, or the number of seconds left if the sleep call was interrumpted.

Hokay. MS Sleep() does milliseconds, and by Nanoda’s post, unix stuff does seconds - and I know from my ancient Borland C++ V1.0 manual that that one did it by seconds in the DOS library.

Thanks everyone! MVS.Net seems to like the windows.h include over the other. Overall class is going well, learning new stuff everyday.

Just a minor design comment: The more operating system or compiler specific your solution, the less cross-platform its going to be.

Sadly, there’s no completely cross-platform sleep solution that doesn’t involve sitting in a loop and spinning (if this is livable, its trivial to implement with a loop, and the standard time() or clock() function).

Yet another frustration for cross-platform development. Anybody wanna help me drag C++ into the next decade with a set of libraries at least equivalent to Java’s? (Heh, programmer flamebait).