Hi Philip,

Well, as I explained in a previous post I know about getchar, and
unfortunately it isn't quite what I am looking for. Besides pausing
the screen I want a function that will act upon a key immediately
rather than waiting for the enter key which getch does and getchar
won't.

However, I have found getchar doesn't always work when pausing the
screen anyway. I have written the following function in C++, and it
fails to do what I want which is to pause until the enter key is
pressed.

void WaitKey()
{
    std::cout << "Press enter to continue:\n";
    std::getchar();
}

Now, in theory that function should prompt the user to press the enter
key and pause the game until the enter key is pressed. Sometimes it
does and sometimes it doesn't. I have written a test program using
getchar as written above and there are cases where the program ignores
the WaitKey() function I wrote and goes and executes the next function
regardless of my instruction to wait. So I don't think pausing the
screen with getchar is necessarily a valid method for cross-platform
pausing the screen. Of course, there may be a difference between the C
implementation of getchar in stdio.h and the C++ implementation in
cstdio. Not sure if that is a difference or not.

Cheers!


On 4/16/14, Philip Bennefall <[email protected]> wrote:
> Hi Thomas,
>
> I tend to find that getchar suits my needs perfectly. Making a call to
> getchar and ignoring the return value does exactly what you describe, and in
>
> a portable way. getch is non-standard as you know so may or may not be
> present on any given target.
>
> Kind regards,
>
> Philip Bennefall

---
Gamers mailing list __ [email protected]
If you want to leave the list, send E-mail to [email protected].
You can make changes or update your subscription via the web, at
http://audyssey.org/mailman/listinfo/gamers_audyssey.org.
All messages are archived and can be searched and read at
http://www.mail-archive.com/[email protected].
If you have any questions or concerns regarding the management of the list,
please send E-mail to [email protected].

Reply via email to