|
From: Ioannis V. <iv...@em...> - 2003-06-09 17:57:38
|
> -----Original Message-----
> From: dev...@li...=20
> [mailto:dev...@li...] On Behalf=20
> Of Andr? Macario Barros
> Sent: Monday, June 09, 2003 7:47 PM
> To: Dev-Cpp-Users
> Subject: [Dev-C++] Escape key sequence
>=20
>=20
> Dear Users,
>=20
> Concerning the Esc escape sequence on the following while,=20
> let me report
> my exact problem:
>=20
> In C, this works:
>=20
> #include <stdio.h>
> #include <stdlib.h>
>=20
> int main()
> {
> char tecla=3D'x';
>=20
> do
> {
> printf(" the key is-->%c\n", tecla);
> }while((tecla =3D getche())!=3D 27);
>=20
> system("pause");
> return 0;
> }
>=20
> I=B4ve changed the getchar by the getche() function and It worked.
>=20
> But, with the following code:
> #include <iostream>
> #include <cstdlib>
> using std::cout;
> using std::endl;
> using std::cin;
> int main()
> {
> char tecla=3D'x';
>=20
> do
> {
> cout << " not escaped yet!!! " << endl;
> }while(tecla =3D cin.get()!=3D 27);
> system("pause");
> return 0;
> }
> --> The behavior of cin.get() seems to me equivalent to=20
> getchar(). And the
> getchar() function stores on the 1st time the caracter and on=20
> the second the
> '\n'. And, it doesn=B4t escape when
> I press the Esc key, ok?
> --> What I need is way to write this second program working=20
> the same way as
> its previous above.
You need unbuffered input (which does not wait for '\n'). This cannot be
done with standard C++ so you have to use a system extension like =
getch() or
getche() as you did.
Ioannis Vranos
=20
* Programming pages: http://www.noicys.freeurl.com
* Alternative URL 1: http://run.to/noicys
* Alternative URL 2: http://www.noicys.cjb.net
|