473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Press any key to continue

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
Nov 17 '05 #1
6 2456

"Bob Altman" <rd*@nospam.com> wrote in message
news:OO****************@TK2MSFTNGP14.phx.gbl...
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

Here's one approach...

char cont;
cout << "Press Enter to continue.\n";
cin.get(cont);
// whatever is next...
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #2
"Peter van der Goes" wrote:

"Bob Altman" <rd*@nospam.com> wrote in message
news:OO****************@TK2MSFTNGP14.phx.gbl...
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

Here's one approach...

char cont;
cout << "Press Enter to continue.\n";
cin.get(cont);
// whatever is next...
--
Peter [MVP Visual Developer]
Jack of all trades, master of none.


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.
Nov 17 '05 #3
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
Nov 17 '05 #4
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;

--
Serge
Nov 17 '05 #5
Bob Altman <rd*@nospam.com> wrote:
[...] 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

--
Sp******@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
Nov 17 '05 #6
Bob Altman wrote:
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.
Nov 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: John Howard | last post by:
I'm trying to write a simple press any key routine, but am having some problems. Here is the routine: void PressAnyKey () { cout << "Press Any Key"; do{}while (!kbhit()); getch(); cout <<...
2
by: Paul Johnston | last post by:
I'm using VB.Net. I've tried using Console.Read() but it requires a line-terminator before it finishes (doesn't that mean it's functionally equivalent to ReadLine() -- why have it then?). I've...
5
by: junk mail | last post by:
My friend is trying to code a small c program where he wants to force the user to press enter and only enter to continue. Currently he is using getchar() with a loop but you can type any number...
5
by: WildHare | last post by:
I have a console application that I want to continue to run until I press a key. How can I get a keypress without stopping execution? Thanks.
9
by: JuanK | last post by:
hello, i'm trying to read a character from console just like getc function in c languaje i'm trying with WINAPI but dont works at this time.. other methods like clear screen works OK with the...
8
by: Timur Ametov | last post by:
Hallo everybody. I'm using Visual Studio 7 and hier is my question. How can i see in Outputwindow after my Programm ended the message "Press any key to continue". Is it possible? Now this window...
9
by: Susan Rice | last post by:
I'm running a simple win32 console application and I want to impliment a "Press any key to continue", so I print that prompt, and then what's the easiest way to impliment reading any key? Do I use...
4
by: kotoro | last post by:
I'm in an intro to computer programming course and just for the purposes of my test drivers and personal implementation, I would like to know if it is possible to force the program to wait for the...
16
by: Karthik | last post by:
Hi, I am trying to port one of my VC++ 6.0 32 bit windows application to Windows XP 64 bit os. This application runs perfectly on windows xp 32bit os without any problem. I used Windows XP...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.