Press any key to continue...

What's an asy way to pause in my program. I want display some info to the user andthe I'll cout "Press any key to continue..." What can I put after that to pause the program until they hit a key. I'd rather not have it so they have to type something and then hit enter. I just want them to a hit on key.
scully12Asked:
Who is Participating?
 
sumant032199Connect With a Mentor Commented:
I think it should be getch() or getche()
depending upon echo is required or not.
0
 
Billy_PilgrimCommented:
two ways:  using DOS or windows 95 / NT use the following call:

system("pause") ;

which is a com prg for dos, and only if you are writing console apps.

otherwise, do the following:

#include <stdio.h>
#include <conio.h>

int main()
{
   fprintf(stderr, "Press any key to continue. . .\n") ;
   _getch() ;  // this will pause you
   return 0 ;
}
0
 
snifongCommented:
Sounds like an answer to me.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Billy_PilgrimCommented:
yes, but here at EE we generally post answers as comments, thereby not locking the questions.  

when the questions are locked experts are not as likely to look at them.

the asker of the question can accept the comment as an answer. . .
0
 
nietodCommented:
>> Sounds like an answer to me.
It depends on the OS and compiler he is using.

scully12, standard C++ provides no way for you to do this because it line-buffers input.  That means the user must press the enter key before input is read, so if you use only standard C++ the user must press at least two keys, the last one being enter.

So if you want it to work based on only one key being pressed, you will have to resort to non-standard or OS-specific procedures.  These procedure may make your program unportable.  Billy_Pilgrim, has suggested a few, there are others, some that are likely to be better depending on the OS and compiler that you are using.
0
 
nietodCommented:
>> yes, but here at EE we generally post
>> answers as comments, thereby not locking
>> the questions.  
Not if you are confident that it is the right answer.  If you are reasonabley confident, lock the answer, this prevents disputes and saves other experts from wasting their time reading the question.  But I agree that in this case, since your "answer" depends on a guess as to what OS he is using, it would be inappropriate to lock the question with an answer.
0
 
nietodCommented:
Sumant, you are once again answering with answers proposed by other experts.  That is unethical.  I could understand it if you did it once by mistake, but you keep doing it, that has to be intentional.  
0
 
scully12Author Commented:
Thanks, the second part did the trick.
0
 
scully12Author Commented:
I want to give the points to Billy_Pilgrim. How can I do that when sumant proposed his sentence as an answer.
0
 
nietodCommented:
You can't now.  When you grade a question the points go to the expert that has answered.  When an expert answers, you either accept that expert's answer awarding them the points, or you can reject that answer, which opens the question up to other experts.  You could have rejected sumant's answer and invited Billy_pilgrim to answer, then graded his answer.  Now you have accepted sumant's answer, so that is not possible.
0
 
Billy_PilgrimCommented:
thanks for clearing that up, nietod.

scully12-- no harm done.  but now you know how it works.
0
 
sumant032199Commented:
I am sorry. I won't do it again.
0
All Courses

From novice to tech pro — start learning today.