123456789101112131415161718192021222324252627282930313233343536
#include <iostream> #include <conio.h> #include <string> using std::cout; using std::endl; using std::string; int main() { string direction[4]={"Up","Down","Left","Right"}; int ch; cout << "Pressing the 'Esc' key, ends the program.." << endl; do { ch = _getch(); switch(ch) { case 72: cout << "The " << direction[0]<< " arrow was pressed.." << endl; break; case 75: cout << "The " << direction[2]<< " arrow was pressed.." << endl; break; case 77: cout << "The " << direction[3]<< " arrow was pressed.." << endl; break; case 80: cout << "The " << direction[1]<< " arrow was pressed.." << endl; } }while(ch!=27);//ESC key cout << endl << endl << "Program finished..." << endl; return 0; }