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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

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
sumant032199Commented:
I think it should be getch() or getche()
depending upon echo is required or not.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.