
*beginner help needed* getche() function
Quote:
> Can someone give me some help with the following program? I'm entering
> it into Visual C++ 1.0 on Windows 95 just like my C++ tutorial book
> says, and it's not recognizing the getche() function. I've also tried
> _getche(), and that's not recognized either. Please, if possible,
> respond through e-mail, but I will check posts here if it's too much of
> a hassle for you.
> // game1.cpp
> #include <iostream.h>
> #include <conio.h> // for _getche()
> void main()
> {
> char dir = 'a';
> int x = 10, y = 10;
> cout << "Type Enter to quit\n";
> while (dir != '\r') // until Enter is typed
> {
> cout << "\nYour location is " << x << ", " << y
> << "\nPress direction key (n, s, e, w): ";
> dir = _getche(); // get character
> if (dir == 'n') // go north
> y--;
> else if (dir == 's') // go south
> y++;
> else if (dir == 'e') // go east
> x++;
> else if (dir == 'w') // go west
> x--;
> } // end while
> }
Evan,
I'm guessing that you have created a Windows program, not a DOS program
in VC++. Unfortunately, _getche() is not available for Windows programs.
(I used VC++ 1.52 to check this out.)
If you look in conio.h you'll find that the declaration of _getche() is
enclosed in a
#ifndef _WINDOWS
#endif
block.
--
Stephen Goodney
All thoughts and opinions are mine alone.