Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / March 2005

Tip: Looking for answers? Try searching our database.

Press any key to continue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Altman - 25 Feb 2005 23:10 GMT
Hi all,

I have an unmanaged console app written in C++.  I can't figure out how to
get C++ to do the standard issue "press any key to continue" thing:

 cout << "Press any key to continue: ";
 cin >> <your code goes here>;

TIA,

 - Bob
Peter van der Goes - 25 Feb 2005 23:35 GMT
> Hi all,
>
[quoted text clipped - 7 lines]
>
>  - Bob

Here's one approach...

char cont;
cout << "Press Enter to continue.\n";
cin.get(cont);
// whatever is next...
Signature

Peter [MVP Visual Developer]
Jack of all trades, master of none.

Škrat Bolfenk - 25 Feb 2005 23:51 GMT
> > Hi all,
> >
[quoted text clipped - 14 lines]
> cin.get(cont);
> // whatever is next...

Try this:

#include <iostream>

using namespace std;

int main()
{
    std::cout << "Hello, world!" << std::endl;

    system("pause");
}

I know it works in std C++ - unmanaged. If any one knows for managed wrapper
please post it.
Bob Altman - 27 Feb 2005 16:10 GMT
Thank you both!  The first approach [cin.get()] serves the intended purpose,
but requires that the user press ENTER.  The second approach
[system("pause")] does exactly what I wanted, but it's seriously
non-portable.

As an exercise for my own education, let me rephrase the question.  Suppose
I have an application that allows the user to enter a command by pressing a
single key on the keyboard.  How would I accept the command into a char
variable?

 - Bob
Serge Baltic - 27 Feb 2005 18:18 GMT
BA> As an exercise for my own education, let me rephrase the question.
BA> Suppose I have an application that allows the user to enter a
BA> command by pressing a single key on the keyboard.  How would I
BA> accept the command into a char variable?

1) getch(), that's for plain C ;)

2) Maybe this:

char ch;
cin >> ch;

Signature

Serge

Hendrik Schober - 03 Mar 2005 01:36 GMT
> [...] Suppose
> I have an application that allows the user to enter a command by pressing a
> single key on the keyboard.  How would I accept the command into a char
> variable?

 I don't think you can do this portably in C++.

>   - Bob

 Schobi

Signature

SpamTrap@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett

Julie - 03 Mar 2005 16:43 GMT
> As an exercise for my own education, let me rephrase the question.  Suppose
> I have an application that allows the user to enter a command by pressing a
> single key on the keyboard.  How would I accept the command into a char
> variable?

There isn't a portable solution.  You either must accept key+enter or resort to
non-portable/platform-specific solutions.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.