C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

wait for keyboard entry ?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Pelo GANDO
Guest





PostPosted: Thu Mar 04, 2004 9:08 am    Post subject: wait for keyboard entry ? Reply with 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
Pelo GANDO
Guest





PostPosted: Thu Mar 04, 2004 9:32 am    Post subject: getch() function Reply with quote



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





PostPosted: Thu Mar 04, 2004 9:47 am    Post subject: Re: [OT, welcome msg] getch() function Reply with quote



"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





PostPosted: Thu Mar 04, 2004 9:52 am    Post subject: Re: [OT, welcome msg] getch() function Reply with quote

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





PostPosted: Thu Mar 04, 2004 9:54 am    Post subject: Re: [OT, welcome msg] getch() function Reply with quote

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





PostPosted: Thu Mar 04, 2004 10:03 am    Post subject: Re: wait for keyboard entry ? Reply with quote

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





PostPosted: Thu Mar 04, 2004 10:04 am    Post subject: Re: wait for keyboard entry ? Reply with quote


"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





PostPosted: Thu Mar 04, 2004 10:14 am    Post subject: Re: [OT, welcome msg] getch() function Reply with quote

"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





PostPosted: Thu Mar 04, 2004 11:20 am    Post subject: Re: [OT, welcome msg] getch() function Reply with quote

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





PostPosted: Thu Mar 04, 2004 12:17 pm    Post subject: Re: [OT, welcome msg] getch() function Reply with quote

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





PostPosted: Thu Mar 04, 2004 12:29 pm    Post subject: Re: wait for keyboard entry ? Reply with quote

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





PostPosted: Thu Mar 04, 2004 3:36 pm    Post subject: Re: [OT, welcome msg] getch() function Reply with quote

Jacob Jensen wrote:
Quote:
What is wrong with
std::cin >> SomeString;

Won't return until <enter> is pressed.

--
Unforgiven

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.