getch() should be in conio.h and it pauses the console until a key is hit and it returns a char for the value of the key pressed. Some special keys (as arrow keys) return two values
I use _getch(); in many of my beginner proggys just because i need the console held open on termination, but I am curious, is there a preferred way to just do a clrscrn and what the _getch accomplishes without having to call it explicitly ? What I mean to say is this: When I call _getch, yes I need the console to stay open. Can't I just do a 'wait' function of some sort on a timer, then term minus user input within defined parameters of the wait function?
There are many ways of keeping the console window open: http://www.cplusplus.com/forum/articles/7312/
C++ has not a real wait function but you can build it using the C time library: http://www.cplusplus.com/reference/clibrary/ctime/clock/ (that example uses 100% CPU on 'wait' function)
To have the best functions for console stuff you might use curses or Windows API.
The curses library also have a getch which works the same way as the getch from conio
Thanks! That example is right on the nailhead for what I am looking for, as I don't really see the point of using _getch() function when having to manually close the console seems redundant avtivity in some cases, where user input is requested, but not known to exist as an predictable occurrence. At any rate, this seems interesting, and seems like a good base to allow an activity to poll for user input (given some tweakage, of course). Thanks again for your speedy reply.
I know how to do it only in windows. I programmed only in windows so far, and I don't think I'll do anyother kind of programming.
The Sleep function allows other programs to use the processor while your program waits. It doesn't use the processor for your program. This is why you don't have 100% CPU, and if you check it will be 0% CPU for your application while it waits.
#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.
Return Value
Zero if the requested time has elapsed, or the number of seconds left to sleep.