I used google trying to find what is the easy way to implement the ubiquitous "Hit any key to continue." in a "console" app (I'm using Visual Studio 2010 atm).

I found the answer above, thank you DCX2. Here is the 2010 version of the answer:


Microsoft: "Use the ISO C++ conformant _kbhit"

(You have do do something like:

while( !_kbhit() );


Could you please state the passage in the C++ Standard that claims _kbhit() is in any way compliant. Include a link to the copy of the C++ Standard you used.

Just because M$ has implemented _kbhit() does not mean any other compiler has. Please list a few compilers that also include _kbhit() in their runtime library.

And _kbhit() inputs nothing. It cannot implement a "press any key" in any way. To claim it does only adds to the ignorance of the previous posts made about it.

[o.t. rant]
Since this thread has already been thoroughly trashed by people more concerned with showing how much smarter they are than the other poster [implicitly bringing themselves down to their level]...

Including yourself with even more incorrect information... :icon_rolleyes:

... I must address a particularly irksome point:

> "It's generally considered rude to resurrect ancient threads, for any reason."

NO! To anyone who says that, please stop it already!!!

I have been reading the Internet since about 1987. That general idea about posting to "old" threads being bad has to be one of the most ignorant ones I have run across in twenty five years... Ugh.
[/o.t. rant]

Since this is your first post here, you are treading on a long-established tradition. If you have nothing new to add to the discussion, resurrecting a thread is frowned upon. Each site has it's own rules and regulations. The "Internet" does not make any rules what-so-ever in this regard. Only someone ignorant about the site in question would make a statement as you have. And to complain about the rules of the site that have been in place for years in his first post he must be pretty full of himself.


While this thread is somewhat alive again, I have always wondered if it would be possible to use __asm to use assembly language to emulate getch(). INT 21 with AH = 07 seems to pop out at me. I just have major trouble with my assembler and I do not fully understand assembly, but I don't see why it wouldn't be possible.


Microsoft: "Use the ISO C++ conformant _kbhit"

Conformant as an extension, not as part of the standard library. You're welcome to quote chapter and verse of the standard that defines _kbhit() and prove me wrong, but in the past people have found it difficult to successfully debate the contents of the standard with me. :)

I have been reading the Internet since about 1987.

Congratulations, but longevity does not in itself give you credibility.

[/o.t. rant]

Yes, please. The last thing we need is another self-righteous doorknob playing net nanny where he holds no authority. Though I find it hilarious how the getch() "controversy" is the single most common catalyst for attracting net nannies.

I have always wondered if it would be possible to use __asm to use assembly language to emulate getch().

Certainly. It would be a waste of time in terms of practicality, but an interesting diversion if you've nothing better to do. ;)

Edited by Narue: n/a


Wow !! Now thats a heated argument. Coming to whats been asked:

Replacement for getch() - getche() (similiar functioning)

Code for taking in a character for password and printing the * after that :

char pwdin[50];

	      {gotoxy(41 + i,11);        //Entering password
	       if(pwdin[i]=='\b')         //'\b' for recognising backspace
		 {gotoxy(40 + i , 11);
		    cout<<" ";
		   {gotoxy(41 + i,11);

The above not only prints a * after every time u enter a character but also holds good for a backspace, so if u mess up while typing.. u can press the backspace button and not only does the * go back one location.. that element is retaken...

Worked for me.. and yes.. needless to specify this is only the snippet.. this is obviously inside main and the necessary declarations are to be done and the header files included !!


Replacement for getch() - getche() (similiar functioning)

If you don't have getch() or don't want to use getch() for portability reasons, getche() is a non-solution because it comes from the same library and has the same portability limitations.



#include "iostream"
#include "conio.h"
 using namespace std;
 void main()
     int a,b;
     cout<<"Addition of 2 numbers\n";
     cout<<"Enter 2 numbers:";
     cout<<"Addition is "<<(a+b);
Votes + Comments
Not only is this a 10-month bump, but if you read ANY of this thread at all, you'd realize why your post is absolutely useless and doesn't solve anything.

Found a snippet somewhere. This may help to other people.

#include <termios.h>
#include <stdio.h>

    static struct termios old, xnew;

    /* Initialize xnew terminal i/o settings */
    void initTermios(int echo) 
      tcgetattr(0, &old); /* grab old terminal i/o settings */
      xnew = old; /* make xnew settings same as old settings */
      xnew.c_lflag &= ~ICANON; /* disable buffered i/o */
      xnew.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
      tcsetattr(0, TCSANOW, &xnew); /* use these xnew terminal i/o settings now */

    /* Restore old terminal i/o settings */
    void resetTermios(void) 
      tcsetattr(0, TCSANOW, &old);

    /* Read 1 character - echo defines echo mode */
    char getch_(int echo) 
      char ch;
      ch = getchar();
      return ch;

    /* Read 1 character without echo */
    char getch(void) 
      return getch_(0);

    /* Read 1 character with echo */
    char getche(void) 
      return getch_(1);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.