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 6 2466
"Bob Altman" <rd*@nospam.com > wrote in message
news:OO******** ********@TK2MSF TNGP14.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.
"Peter van der Goes" wrote: "Bob Altman" <rd*@nospam.com > wrote in message news:OO******** ********@TK2MSF TNGP14.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.
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
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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 << endl;
}
|
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 tried
Console.In.ReadBlock(), too, with no success.
So, along these lines, how would I implement, simply, a "Press Any Key to
Continue" routine or, more complex, a text menu in a Console app to get a
single character?
i.e.
|
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 of
characters, which are echoed to screen before you have to press enter.
For example:-
do
{ /* Begin loop */
|
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.
|
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 WINAPI.. an others to
please helpe and try understandme because i dont speak in english
tx
| |
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 will closed automatisch.
Thank you
|
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
'getchar', or 'gets', or some get function? or 'cin', or what's
an easy way?
What I want is the program to pause before exiting so the user
can read whatever messages there are before the console window
disappears.
|
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 enter key before proceeding without allowing the user to type in anything. I don't really have any experience with the buffered reader, we were provided with an IO class that handles inputs. Currently I solve it with a String input that doesnt go...
|
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 64 bit build environment (Debug) from PSDK for
windows 2003 R2 to port my application, and created the suitable
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |