473,396 Members | 1,970 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,396 software developers and data experts.

something like kbhit

How can i know if there are characters in the standard input using only
standard c++? I want to stop a loop when any key is pressed.
--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Jul 23 '05 #1
7 4307
On Thu, 09 Jun 2005 18:49:23 GMT, DevarajA <no@spam.com> wrote:
How can i know if there are characters in the standard input using only
standard c++? I want to stop a loop when any key is pressed.


As Artie said, you can't. Have a look at the FAQ:
http://www.parashift.com/c++-faq-lite/, in particular 15.17.

rossum

The ultimate truth is that there is no ultimate truth
Jul 23 '05 #2
rossum ha scritto:
On Thu, 09 Jun 2005 18:49:23 GMT, DevarajA <no@spam.com> wrote:

How can i know if there are characters in the standard input using only
standard c++? I want to stop a loop when any key is pressed.

As Artie said, you can't. Have a look at the FAQ:
http://www.parashift.com/c++-faq-lite/, in particular 15.17.

rossum

The ultimate truth is that there is no ultimate truth


The faq talks about a keyboard.. and I know that c++ doesnt require a
keyboard, but somewhere there must be an input stream, so I just want to
know if there is even one character on it without stopping the program
(the function looks at the stream, if it's empty returns 0, otherwise it
returns 1). I think this could be possible.

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Jul 23 '05 #3
DevarajA wrote:
rossum ha scritto:
On Thu, 09 Jun 2005 18:49:23 GMT, DevarajA <no@spam.com> wrote:

How can i know if there are characters in the standard input using
only standard c++? I want to stop a loop when any key is pressed.

As Artie said, you can't. Have a look at the FAQ:
http://www.parashift.com/c++-faq-lite/, in particular 15.17.


The faq talks about a keyboard.. and I know that c++ doesnt require a
keyboard, but somewhere there must be an input stream, so I just want
to know if there is even one character on it without stopping the
program (the function looks at the stream, if it's empty returns 0,
otherwise it returns 1). I think this could be possible.


No, it really, really, really isn't. There are frequently OS-specific libraries that will do what you want, though. Have
you actually looked at the FAQ 15.17?

--
Lionel B

Jul 23 '05 #4
Lionel B ha scritto:
DevarajA wrote:
rossum ha scritto:
On Thu, 09 Jun 2005 18:49:23 GMT, DevarajA <no@spam.com> wrote:

How can i know if there are characters in the standard input using
only standard c++? I want to stop a loop when any key is pressed.
As Artie said, you can't. Have a look at the FAQ:
http://www.parashift.com/c++-faq-lite/, in particular 15.17.


The faq talks about a keyboard.. and I know that c++ doesnt require a
keyboard, but somewhere there must be an input stream, so I just want
to know if there is even one character on it without stopping the
program (the function looks at the stream, if it's empty returns 0,
otherwise it returns 1). I think this could be possible.

No, it really, really, really isn't. There are frequently OS-specific libraries that will do what you want, though. Have
you actually looked at the FAQ 15.17?


Yes but i can't get it working. Anyway i'm already using a non-standard
function that works perfectly, I just wanted to make it standard to
avoid problems when porting.

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Jul 23 '05 #5
DevarajA wrote:
Lionel B ha scritto:
DevarajA wrote:
rossum ha scritto:

On Thu, 09 Jun 2005 18:49:23 GMT, DevarajA <no@spam.com> wrote:

> How can i know if there are characters in the standard input using
> only standard c++? I want to stop a loop when any key is pressed.

As Artie said, you can't. Have a look at the FAQ:
http://www.parashift.com/c++-faq-lite/, in particular 15.17.

The faq talks about a keyboard.. and I know that c++ doesnt require
a keyboard, but somewhere there must be an input stream, so I just
want to know if there is even one character on it without stopping
the program (the function looks at the stream, if it's empty
returns 0, otherwise it returns 1). I think this could be possible.
No, it really, really, really isn't. There are frequently
OS-specific libraries that will do what you want, though. Have you
actually looked at the FAQ 15.17?


Yes but i can't get it working.


What's the problem (I'm assuming you're on a Posix system)? If it's C++ related, why not post it here? Else in a Unix
programmers ng, maybe?
Anyway i'm already using a
non-standard function that works perfectly, I just wanted to make it
standard to avoid problems when porting.


Right... well as I guess you've gathered by now, you're out of luck there. If you can get the Posix solution working
that will at least increase your portability to a lot of systems (and you've already got kbhit and all the conio.h stuff
on Win32... don't know about Mac).

Cheers,

--
Lionel B

Jul 23 '05 #6
Lionel B ha scritto:
DevarajA wrote:
Lionel B ha scritto:
DevarajA wrote:
rossum ha scritto:
>On Thu, 09 Jun 2005 18:49:23 GMT, DevarajA <no@spam.com> wrote:
>
>
>>How can i know if there are characters in the standard input using
>>only standard c++? I want to stop a loop when any key is pressed.
>
>As Artie said, you can't. Have a look at the FAQ:
>http://www.parashift.com/c++-faq-lite/, in particular 15.17.

The faq talks about a keyboard.. and I know that c++ doesnt require
a keyboard, but somewhere there must be an input stream, so I just
want to know if there is even one character on it without stopping
the program (the function looks at the stream, if it's empty
returns 0, otherwise it returns 1). I think this could be possible.

No, it really, really, really isn't. There are frequently
OS-specific libraries that will do what you want, though. Have you
actually looked at the FAQ 15.17?


Yes but i can't get it working.

What's the problem (I'm assuming you're on a Posix system)? If it's C++ related, why not post it here? Else in a Unix
programmers ng, maybe?


the faq tells me to "poll", but i don't know how to poll

--
Devaraja (Xdevaraja87^gmail^c0mX)
Linux Registerd User #338167
http://counter.li.org
Jul 23 '05 #7
DevarajA wrote:
Lionel B ha scritto:
DevarajA wrote:
Lionel B ha scritto:

DevarajA wrote:
> rossum ha scritto:
>
>
>> On Thu, 09 Jun 2005 18:49:23 GMT, DevarajA <no@spam.com> wrote:
>>
>>
>>> How can i know if there are characters in the standard input using
>>> only standard c++? I want to stop a loop when any key is pressed.
>>
>>
>> As Artie said, you can't. Have a look at the FAQ:
>> http://www.parashift.com/c++-faq-lite/, in particular 15.17.
>
>
> The faq talks about a keyboard.. and I know that c++ doesnt require
> a keyboard, but somewhere there must be an input stream, so I just
> want to know if there is even one character on it without stopping
> the program (the function looks at the stream, if it's empty
> returns 0, otherwise it returns 1). I think this could be possible.
No, it really, really, really isn't. There are frequently
OS-specific libraries that will do what you want, though. Have you
actually looked at the FAQ 15.17?
Yes but i can't get it working.


What's the problem (I'm assuming you're on a Posix system)? If it's
C++ related, why not post it here? Else in a Unix
programmers ng, maybe?

the faq tells me to "poll", but i don't know how to poll


select()
http://www.opengroup.org/onlinepubs/...ns/select.html

poll()
http://www.opengroup.org/onlinepubs/...ions/poll.html

select and poll serve essentially the same purpose. select is a bit
easier to use, in my opinion. poll is probably a bit more efficient on
most systems (though if you are just monitoring stdin that won't matter).

-Alan
Jul 23 '05 #8

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

Similar topics

0
by: dbrown2 | last post by:
I'm having some trouble using kbhit inside the editor enviroments. I'm using win2000 with Python2.3 and win32all v157 versions. Any pointer on how this should be handled would be appreciated. Is...
1
by: Hans Georg Krauthaeuser | last post by:
Hey all, this is probably a FAQ, but I didn't found the answer... I use msvcrt.kbhit() to check for a user keyboard event on windows. But now, I would prefer to make the module independent...
17
by: hugo27 | last post by:
June 28, 2004 I'm interested in finding a way to test the keyboard buffer for MT/Not MT. Tried kbhit() in system.h but it didn't do what I thought it would from reading the literature. Samples:...
6
by: exquisitus | last post by:
Hi all, I'm porting a DOS application to run on Linux. I need to replace this function or use an equivalent. Anyone knows how or where I can get this function's equivalent (or maybe someones...
1
by: Carsten Orthbandt | last post by:
This code: ---snip--- #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <stdio.h> #include <tchar.h> #include <conio.h> int _tmain(int argc, _TCHAR*...
45
by: simnav | last post by:
In the following code something strange happens ! If I keep pressed any of ALT+Arrow, keys, they are extracted two times from buffer then getch seems to stop; if I release and press again ALT+arrow...
2
by: sk1988jun | last post by:
can anyone please tell me equivalent function in matlab for kbhit() which is a c fuction
1
by: palani12kumar | last post by:
Can anybody tell me, how the kbhit() works?
1
by: SpecialKay | last post by:
hey guys, i have a threaded program, i have loop that contunes until i get a kbhit() then, i playback repetively untill i get another kbhit(). EDIT: the first kbhit happens on a child thread of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.