"Press any key to continue" type function?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2007
Posts: 35
Reputation: Ratte is an unknown quantity at this point 
Solved Threads: 0
Ratte's Avatar
Ratte Ratte is offline Offline
Light Poster

"Press any key to continue" type function?

 
0
  #1
Nov 13th, 2007
I've searched all over the place and I cannot seem to find a well working, reliable solution to this that is not platform specific.

Here is what I have:

Main menu of a class (while loop with 0 as exit).
User selects choices.
Choice calls class function to carry out the specific request.

I want the result of each of the functions to stay on screen until the user presses any key (and doesn't have to press enter to confirm it) and then the menu is called again.

Is there an easy way to do this?

PS. I've seen an implementations with cin.get(ch) or cin.ignore(1,0), but neither work in my situation. After a certain function is done, the menu is called as if bypassing the get character line completely.

Thanks!
Last edited by Ratte; Nov 13th, 2007 at 2:23 am.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: "Press any key to continue" type function?

 
0
  #2
Nov 13th, 2007
Can't be done. Change your message to Press ENTER to continue and just use the standard I/O functions.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 5
Reputation: Garock is an unknown quantity at this point 
Solved Threads: 0
Garock Garock is offline Offline
Newbie Poster

Re: "Press any key to continue" type function?

 
0
  #3
Nov 13th, 2007
how bout using getch() or getche() ?
note. if u're using vc++, both are using leading underscore such as _getch() and _getche()
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 1,951
Reputation: Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of Duoas has much to be proud of 
Solved Threads: 214
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: "Press any key to continue" type function?

 
0
  #4
Nov 13th, 2007
getch() and variants are not cross-platform.

Your best bet is to use the curses library. There are three variants: curses (the oldest and most basic), ncurses (a big improvement), and pdcurses (ditto). Most (if not all) Unix/Linux platforms have at least curses, if not ncurses. PDCurses, in addition to Unix variants, comes available on DOS, OS/2, Windows, Plan 9, and the Amiga.

That covers many desktop systems people will be using (including OS X), but nowhere near all.

Here's an example in another post of mine --doing exactly what you want.

Keep in mind, like WaltP said, there is no truly cross-platform method. Also, once you start using curses you cannot use the standard C/C++ I/O --it is one or the other.

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: "Press any key to continue" type function?

 
0
  #5
Nov 13th, 2007
I find it interesting that, given the following requirement:
Originally Posted by Ratte View Post
I've searched all over the place and I cannot seem to find a well working, reliable solution to this that is not platform specific.
the solutions provided are:

Originally Posted by Garock View Post
how bout using getch() or getche() ?
note. if u're using vc++, both are using leading underscore such as _getch() and _getche()
Originally Posted by Duoas View Post
getch() and variants are not cross-platform.

Your best bet is to use the curses library. There are three variants: curses (the oldest and most basic), ncurses (a big improvement), and pdcurses (ditto). Most (if not all) [implication being might not work on all] Unix/Linux platforms have at least curses, if not ncurses. PDCurses, in addition to Unix variants, comes available on DOS, OS/2, Windows, Plan 9, and the Amiga. [implication: different packages for different platforms]

That covers many desktop systems people will be using (including OS X), but nowhere near all. [can't be done on all platforms]
IOW: cannot be done, which is what I said originally...
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,574
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 709
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: "Press any key to continue" type function?

 
0
  #6
Nov 13th, 2007
>IOW: cannot be done, which is what I said originally...
Then again, "cannot be done" is pretty darn useless as an answer. I imagine alternatives were provided because they come close to the requirement even though it isn't an exact match.

Personally, I don't see why there's a need for "any key" when Enter works just fine. Statistics show that when asked to press any key, users will typically press the space bar or the Enter key, so by requiring Enter, you're only removing one key as a potential option in the average case. Supporting the space bar is hardly worth throwing away portability and adding complexity.
Last edited by Narue; Nov 13th, 2007 at 12:38 pm.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 35
Reputation: Ratte is an unknown quantity at this point 
Solved Threads: 0
Ratte's Avatar
Ratte Ratte is offline Offline
Light Poster

Re: "Press any key to continue" type function?

 
0
  #7
Nov 13th, 2007
I must say I'm surprised that there is no simple solution to this in such a complex language.

Actually, ENTER would work just as well for me, however, I do not understand why, but my program skips through the line cin.get(ch) line altogether, so it doesn't ask for anything when it should.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,574
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 709
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: "Press any key to continue" type function?

 
0
  #8
Nov 13th, 2007
>I must say I'm surprised that there is no simple solution to this in such a complex language.
That's because you don't fully understand the issues involved.

>my program skips through the line cin.get(ch) line altogether
It doesn't skip anything. cin.get is working as designed, but a prior formatted input request left a newline in the stream. See this for more details.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: krigath is an unknown quantity at this point 
Solved Threads: 0
krigath krigath is offline Offline
Newbie Poster

Re: "Press any key to continue" type function?

 
0
  #9
Jan 31st, 2009
there is a really easy way to do this....

system("PAUSE");

does it all.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,136
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 530
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: "Press any key to continue" type function?

 
0
  #10
Jan 31st, 2009
Originally Posted by krigath View Post
there is a really easy way to do this....

system("PAUSE");

does it all.
he wants something platform independant. That only works on windows.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC