| View previous topic :: View next topic |
| Author |
Message |
Pelo GANDO Guest
|
Posted: Thu Mar 04, 2004 9:08 am Post subject: wait for keyboard entry ? |
|
|
Hi everybody,
It's me again...Pelo, for an other beginner question...
What the code should be in C++ to wait for a keyboard entry in order to
execute the sequal of my program...
|
|
| Back to top |
|
 |
Pelo GANDO Guest
|
Posted: Thu Mar 04, 2004 9:32 am Post subject: getch() function |
|
|
I found by myself...
#include <conio.h>
cout << "Press any key to terminate this program. " ; getch();
The getch() function call causes the program to wait for a single keystroke.
"Pelo GANDO"
c26rlv$i9v$1 (AT) news-reader3 (DOT) wanadoo.fr...
| Quote: | Hi everybody,
It's me again...Pelo, for an other beginner question...
What the code should be in C++ to wait for a keyboard entry in order to
execute the sequal of my program...
|
|
|
| Back to top |
|
 |
Mike Wahler Guest
|
Posted: Thu Mar 04, 2004 9:47 am Post subject: Re: [OT, welcome msg] getch() function |
|
|
"Pelo GANDO" <o0593m (AT) hotmail (DOT) com> wrote
| Quote: | I found by myself...
#include
cout << "Press any key to terminate this program. " ; getch();
The getch() function call causes the program to wait for a single
keystroke. |
But alas it's not part of the C++ language. It's an
'extension' provided by your implementation, not topical
here. Here we discuss the ISO standard C++ langauge, which
has no means to do what you're asking.
See:
http://www.slack.net/~shiva/welcome.txt
-Mike
|
|
| Back to top |
|
 |
Pelo GANDO Guest
|
Posted: Thu Mar 04, 2004 9:52 am Post subject: Re: [OT, welcome msg] getch() function |
|
|
thank you !
"Mike Wahler" <mkwahler (AT) mkwahler (DOT) net> a écrit dans le message de news:
5XC1c.20812$aT1.4581 (AT) newsread1 (DOT) news.pas.earthlink.net...
| Quote: | "Pelo GANDO" <o0593m (AT) hotmail (DOT) com> wrote in message
news:c26t39$8t0$1 (AT) news-reader5 (DOT) wanadoo.fr...
I found by myself...
#include
cout << "Press any key to terminate this program. " ; getch();
The getch() function call causes the program to wait for a single
keystroke.
But alas it's not part of the C++ language. It's an
'extension' provided by your implementation, not topical
here. Here we discuss the ISO standard C++ langauge, which
has no means to do what you're asking.
See:
http://www.slack.net/~shiva/welcome.txt
-Mike
|
|
|
| Back to top |
|
 |
Pelo GANDO Guest
|
Posted: Thu Mar 04, 2004 9:54 am Post subject: Re: [OT, welcome msg] getch() function |
|
|
Sir,
How would you do in ISO standard C++...
I would like knwo from you...
Thank you
"Mike Wahler" <mkwahler (AT) mkwahler (DOT) net> a écrit dans le message de news:
5XC1c.20812$aT1.4581 (AT) newsread1 (DOT) news.pas.earthlink.net...
| Quote: | "Pelo GANDO" <o0593m (AT) hotmail (DOT) com> wrote in message
news:c26t39$8t0$1 (AT) news-reader5 (DOT) wanadoo.fr...
I found by myself...
#include
cout << "Press any key to terminate this program. " ; getch();
The getch() function call causes the program to wait for a single
keystroke.
But alas it's not part of the C++ language. It's an
'extension' provided by your implementation, not topical
here. Here we discuss the ISO standard C++ langauge, which
has no means to do what you're asking.
See:
http://www.slack.net/~shiva/welcome.txt
-Mike
|
|
|
| Back to top |
|
 |
Jacob Jensen Guest
|
Posted: Thu Mar 04, 2004 10:03 am Post subject: Re: wait for keyboard entry ? |
|
|
| Quote: | What the code should be in C++ to wait for a keyboard entry in order to
execute the sequal of my program...
|
You can use std::cin which redirects input from stdin (your keyboard) to a
string in your program. Example
#include <string>
int main()
{
std::string sInputString;
// Wait for input from stdin (the keyboard)
std::cin >> sInputString;
// Print out to the screen what the user just input
std::cout << "The user just input the following string: " <<
sInputString << std::endl;
}
I hope this helps
|
|
| Back to top |
|
 |
amateur Guest
|
Posted: Thu Mar 04, 2004 10:04 am Post subject: Re: wait for keyboard entry ? |
|
|
"Pelo GANDO" <o0593m (AT) hotmail (DOT) com> wrote
| Quote: | Hi everybody,
It's me again...Pelo, for an other beginner question...
What the code should be in C++ to wait for a keyboard entry in order to
execute the sequal of my program...
|
c++ doesn't have such a concept.
If you work under character environments such as unix or old dos you'll
usually call a single function to achieve that. Non standard headers like
<conio.h> for dos may provide what you're looking for. Others will point you
to correct newsgroups.
If you work under some GUI like Windows or the X, than your whole program
concept changes. You wait for specific messages/callbacks from your
OS/GUI/Framework manager or whatever. And that's a complex topic which is
not discussed here.
|
|
| Back to top |
|
 |
Mike Wahler Guest
|
Posted: Thu Mar 04, 2004 10:14 am Post subject: Re: [OT, welcome msg] getch() function |
|
|
"Pelo GANDO" <o0593m (AT) hotmail (DOT) com> wrote
| Quote: | Sir,
How would you do
|
[nonblocking input]
| Quote: | in ISO standard C++...
I would like knwo from you...
|
Like I said, it cannot be done with standard C++.
You'll need to use an extension, such as the
one you mentioned. However you should note
that this will only work with that particular
compiler, others will have their own way, if
they have any at all. When you encounter this
situation, I advise you to isolate and clearly
identify such uses, so porting will be easier
when the time comes.
-Mike
|
|
| Back to top |
|
 |
Jacob Jensen Guest
|
Posted: Thu Mar 04, 2004 11:20 am Post subject: Re: [OT, welcome msg] getch() function |
|
|
What is wrong with
std::cin >> SomeString;
Jacob
"Mike Wahler" <mkwahler (AT) mkwahler (DOT) net> wrote
| Quote: | "Pelo GANDO" <o0593m (AT) hotmail (DOT) com> wrote in message
news:c26ucq$qcb$1 (AT) news-reader2 (DOT) wanadoo.fr...
Sir,
How would you do
[nonblocking input]
in ISO standard C++...
I would like knwo from you...
Like I said, it cannot be done with standard C++.
You'll need to use an extension, such as the
one you mentioned. However you should note
that this will only work with that particular
compiler, others will have their own way, if
they have any at all. When you encounter this
situation, I advise you to isolate and clearly
identify such uses, so porting will be easier
when the time comes.
-Mike
|
|
|
| Back to top |
|
 |
Rolf Magnus Guest
|
Posted: Thu Mar 04, 2004 12:17 pm Post subject: Re: [OT, welcome msg] getch() function |
|
|
Mike Wahler wrote:
| Quote: | "Pelo GANDO" <o0593m (AT) hotmail (DOT) com> wrote in message
news:c26ucq$qcb$1 (AT) news-reader2 (DOT) wanadoo.fr...
Sir,
How would you do
[nonblocking input]
|
How would waiting for keyboard input be _non_blocking?
|
|
| Back to top |
|
 |
Tor Husabø Guest
|
Posted: Thu Mar 04, 2004 12:29 pm Post subject: Re: wait for keyboard entry ? |
|
|
Jacob Jensen wrote:
| Quote: | What the code should be in C++ to wait for a keyboard entry in order to
execute the sequal of my program...
You can use std::cin which redirects input from stdin (your keyboard) to a
string in your program. Example
#include <string
int main()
{
std::string sInputString;
// Wait for input from stdin (the keyboard)
std::cin >> sInputString;
// Print out to the screen what the user just input
std::cout << "The user just input the following string: "
sInputString << std::endl;
}
I hope this helps
This would require the user to press Enter before anything would happen, |
and that's probably not good enough. (Assuming the 'Press any key to
continue' thing is what he's after.) :)
But printing 'Press Enter to continue.' and then reading from
std::cin could be a viable solution, although less elegant then
conio's getch() and the likes.
Tor
|
|
| Back to top |
|
 |
Unforgiven Guest
|
Posted: Thu Mar 04, 2004 3:36 pm Post subject: Re: [OT, welcome msg] getch() function |
|
|
Jacob Jensen wrote:
| Quote: | What is wrong with
std::cin >> SomeString;
|
Won't return until <enter> is pressed.
--
Unforgiven
|
|
| Back to top |
|
 |
|