![]() |
| | #1 |
| Registered User Join Date: Sep 2004
Posts: 2
| RFC: C++ "Hit any key to continue..." solution Specificaly, a better solution than any that are given here: http://faq.cprogramming.com/cgi-bin/...&id=1043284385 I have come up with (I think) a cross platform, C++ solution that takes care of a terminal environment that does input line buffering Code: #include <iostream>
using namespace std;
int main() {
cout << "\nPress any key to continue..." << endl;
streambuf *pbuf;
pbuf=cin.rdbuf()->setbuf(NULL, 1);
pbuf->sgetc();
return 0;
}
|
| flakier is offline | |
| | #2 |
| Registered User Join Date: Sep 2004 Location: California
Posts: 2,845
| Doesn't compile on my machine. error C2248: 'setbuf' : cannot access protected member declared in class 'std::basic_streambuf<char,struct std::char_traits<char> >' |
| bithub is offline | |
| | #3 |
| C++ Developer Join Date: Jun 2002 Location: UWaterloo
Posts: 2,718
| It doesn't compile under GCC 3.3.4 on Debian Linux either: Code: matt@debianbox c $ g++ -pedantic -Wall flakier.cpp /usr/include/c++/3.3/streambuf: In function `int main()': /usr/include/c++/3.3/streambuf:713: error: `std::basic_streambuf<_CharT, _Traits>* std::basic_streambuf<_CharT, _Traits>::setbuf(_CharT*, int) [with _CharT = char, _Traits = std::char_traits<char>]' is protected flakier.cpp:7: error: within this context matt@debianbox c $
__________________ Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie |
| XSquared is offline | |
| | #4 |
| Registered User Join Date: Sep 2004
Posts: 2
| Hmm, back to the drawing board! I've got an old gcc-2.95.2.1 and at home VS.NET2002 I think I saw something on technet about streambuf::setbuf being replaced by pubsetbuf() Thanks for the reports :) ~Jason |
| flakier is offline | |
| | #5 |
| Registered User Join Date: May 2003
Posts: 2,787
| eh, what's wrong with cin.get()?
__________________ Join is in our Unofficial Cprog IRC channel Server: irc.phoenixradio.org Channel: #Tech Team Cprog Folding@Home: Team #43476 Download it Here Detailed Stats Here More Detailed Stats 52 Members so far, are YOU a member? Current team score: 1223226 (ranked 374 of 45152) The CBoard team is doing better than 99.16% of the other teams Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374) Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT |
| major_small is offline | |
| | #6 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,368
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #7 |
| VA National Guard Join Date: May 2004 Location: Manassas, VA USA
Posts: 902
| with cin.get() you are restricted to only hitting, "Enter" as opposed to system("pause") which will allow you to hit any key to continue. (although it is non-portable/OS dependant) btw I am waiting for a portable alternative to cin.get() that will allow the user to "hit any key to continue".. mainly so I can use it in my programs
__________________
Last edited by The Brain; 09-02-2004 at 08:36 AM. |
| The Brain is offline | |
| | #8 |
| Registered User Join Date: Dec 2002
Posts: 546
| You could just use preprocessors to compile one method if it is being compiled under Windows and another method if it is under Linux. |
| Frobozz is offline | |
| | #9 | |
| Registered User Join Date: May 2003
Posts: 2,787
| Quote:
__________________ Join is in our Unofficial Cprog IRC channel Server: irc.phoenixradio.org Channel: #Tech Team Cprog Folding@Home: Team #43476 Download it Here Detailed Stats Here More Detailed Stats 52 Members so far, are YOU a member? Current team score: 1223226 (ranked 374 of 45152) The CBoard team is doing better than 99.16% of the other teams Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374) Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT | |
| major_small is offline | |
| | #10 |
| C++ Developer Join Date: Jun 2002 Location: UWaterloo
Posts: 2,718
| Well, it's not included in GCC 3.3.4 on my Debian Linux box.
__________________ Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie |
| XSquared is offline | |
| | #11 | |
| Registered User Join Date: May 2003
Posts: 2,787
| Quote:
i've only really tried it on an old borland compiler, Dev-C++ (migw port of gcc), MSVC (who knows), and G++ (version ?)
__________________ Join is in our Unofficial Cprog IRC channel Server: irc.phoenixradio.org Channel: #Tech Team Cprog Folding@Home: Team #43476 Download it Here Detailed Stats Here More Detailed Stats 52 Members so far, are YOU a member? Current team score: 1223226 (ranked 374 of 45152) The CBoard team is doing better than 99.16% of the other teams Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374) Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT | |
| major_small is offline | |
| | #12 |
| & the hat of GPL slaying Join Date: Sep 2001
Posts: 5,730
| One thing to remember is that a standard solution doesn't have to preform a solution the same way on every machine, just provide a standard interface AND a standard result. How you go from the interface to the result can change depending on the environment. As Frobozz said you can use preproccessor directives to decide which solution to use. For a *nix solution I posted one at: faq: cached input with mygetch(). Once I find the updated code on my computer and verify that it works I'll post a more c++ based solution. |
| Thantos is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| RFC - Simple Encryption | Nor | C++ Programming | 11 | 02-16-2009 04:59 PM |
| "action on key hold" programs? | siddharth2212 | C++ Programming | 11 | 07-29-2007 11:19 AM |
| suspend for key without the ugly press any key to continue............... | Stealth | C++ Programming | 1 | 10-07-2001 12:27 AM |
| Pause or press any key to continue | muffin | C Programming | 3 | 09-12-2001 12:26 PM |