PDA

View Full Version : key press



0927
11-11-2001, 07:01 PM
before i started learning c++ i learned visual basic and in it there was a type of thing to do key press how do i do it in c++ to where its like

cout<<"Enter commmand"<<endl;
//user presses a
cout<<"You enterd a"<<endl;

something like that

qwertiop
11-11-2001, 07:32 PM
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
char key;
key=getch();
cout<<"you entered "<<key<<endl;
system("PAUSE");
return 0;
}

Yoshi
11-12-2001, 07:06 PM
or this...

#include<stdio.h>
#include<iostream.h>

main(){
cout << "Enter a character: ";
getche();
}

//the getche() function automatically outputs the pressed character to the screen.