|
From: Ioannis V. <no...@ho...> - 2002-03-22 21:49:36
|
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...] On Behalf
> Of Brian McCall
> Sent: Friday, March 22, 2002 11:37 PM
> To: dev...@li...
> Subject: Re: [Dev-C++] Getch()? How???
>
>
> To use getch() properly, you must have cout << endl; be the
> last statement you make before using getch(). Otherwise it
> will either wait for an endline, or it will output everything
> after the last cout << endl; statement AFTER the user presses a key.
>
> Ex:
>
> void main() {
> cout << "Daniel" << endl;
> getch();
> }
>
> displays "Daniel", advances to next line, then waits for user
> to strike a key.
>
>
> void main() {
> cout << "Daniel";
> getch();
> }
>
> presents user with a blank console and waits for user to
> press any key before displaying "Daniel".
This displays "Daniel" first and then waits for a key in my system.
>
>
> void main() {
> cout << "Daniel" << endl << "Bob";
> getch();
> }
>
> displays "Daniel", advances to next line, waits for user to
> press a key, then displays "Bob" (does not display the
> character pressed by the user).
endl flashes the stream, so to guarantee that the output is displayed
before the getch() we could use endl indeed. But getch() is not portable
anyway.
Ioannis
* Ioannis Vranos
* Programming pages: http://www.noicys.d2g.com
* Alternative URL: http://run.to/noicys
|