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:

http://msdn.microsoft.com/en-us/library/58w7c94c.aspx

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. ;)

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];

while(pwdin[i]!='\r')
	      {gotoxy(41 + i,11);        //Entering password
		pwdin[i]=getch();
	       if(pwdin[i]=='\b')         //'\b' for recognising backspace
		 {gotoxy(40 + i , 11);
		    cout<<" ";
		  if(i==0)
		     {}
		  else
		      --i;
		 }
	       else
		   {gotoxy(41 + i,11);
		      cout<<"*";
		      ++i;
		    }
	      }
	  pwdin[x]='\0';

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.

HERE'S THE SOLUTION FOR VC++:

#include "iostream"
#include "conio.h"
 using namespace std;
 void main()
 {
     int a,b;
     cout<<"Addition of 2 numbers\n";
     cout<<"Enter 2 numbers:";
     cin>>a>>b;
     cout<<"Addition is "<<(a+b);
     _getch();
 }
commented: 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. -1

getch() is used for constant window for the o/p.

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;
      initTermios(echo);
      ch = getchar();
      resetTermios();
      return ch;
    }

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

    /* Read 1 character with echo */
    char getche(void) 
    {
      return getch_(1);
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.