-
waiting for a keypress
Hey I'm working on a program for a class I'm in and I'm wondering how you would tell the program to wait until any key is pressed. I'm displaying a bunch of information and I would like to have the computer wait for any key (or a specific one if it has to be) to be pressed before going back to the main menu. Is this possible?
Thanks!
-
-
using the conio header file
use getch() which waits for a key to be pressed before continuing
Code:
#include <conio.h>
#include <stdio.h>
int main()
{
printf("TON OF INFO\n");
getch();
return 0;
}
// NOW FOR C++ VERSION
#include <iostream.h>
#include <conio.h>
int main()
{
cout<<"TON OF INFO"<<endl;
getch();
return 0;
}
// getch() will stop after the endl; in C++
// not sure bout the C though.
usually it works like:
cout<<"Press any key to continue"<<endl;
getch();
-
This is what I use, you need a specific key stroke, but it is as portable as it gets.
Code:
printf("Please press <ENTER> to continue.");
while(getchar() != '\n');
-
Thanks