Topic: Stdio single character
Author: spoon.menright@cts.com (Mike Enright)
Date: 1997/10/12 Raw View
fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson) wrote:
>.... The Ada standard is quite practical, and it includes
>support for getting a keystroke without requiring a user to press enter.
>
>As it happens, the C++ draft standard does not include such support.
I've thought, for years, that this could be standardized, and I think
it would advance this discussion if you would describe the part of Ada
you referred to. (I don't know the Ada standard at all, btw).
--
Mike Enright
menright@cts.com
http://www.users.cts.com/sd/m/menright/
Cardiff-by-the-Sea, California, USA
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/10/12 Raw View
spoon.menright@cts.com (Mike Enright) writes:
>fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson) wrote:
>
>>.... The Ada standard is quite practical, and it includes
>>support for getting a keystroke without requiring a user to press enter.
>>
>>As it happens, the C++ draft standard does not include such support.
>
>I've thought, for years, that this could be standardized, and I think
>it would advance this discussion if you would describe the part of Ada
>you referred to. (I don't know the Ada standard at all, btw).
Well, perhaps it is simpler if I just quote it.
| A.10.7 Input-Output of Characters and Strings
|
| (9)
| procedure Get_Immediate(File : in File_Type;
| Item : out Character);
| procedure Get_Immediate(Item : out Character);
|
| (10)
|
| Reads the next character, either control or graphic, from the
| specified File or the default input file.
[...]
| (11)
| procedure Get_Immediate(File : in File_Type;
| Item : out Character;
| Available : out Boolean);
| procedure Get_Immediate(Item : out Character;
| Available : out Boolean);
|
| (12)
|
| If a character, either control or graphic, is available from the
| specified File or the default input file, then the character
| is read; Available is True and Item contains the value of
| this character. If a character is not available, then
| Available is False and the value of Item is not specified.
[...]
| Implementation Advice
|
| (23)
| The Get_Immediate procedures should be implemented with
| unbuffered input. For a device such as a keyboard, input should
| be ``available'' if a key has already been typed, whereas for a
| disk file, input should always be available except at end of
| file. For a file associated with a keyboard-like device, any
| line-editing features of the underlying operating system should
| be disabled during the execution of Get_Immediate.
|
|
| NOTES
|
| (24)
|
| (26) Get_Immediate can be used to read a single key from the
| keyboard ``immediately''; that is, without waiting for an end
| of line. In a call of Get_Immediate without the parameter
| Available, the caller will wait until a character is
| available.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: spoon.menright@cts.com (Mike Enright)
Date: 1997/10/15 Raw View
fjh@mundook.cs.mu.OZ.AU (Fergus Henderson) wrote:
>spoon.menright@cts.com (Mike Enright) writes:
>
>>fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson) wrote:
>>
>>>.... The Ada standard is quite practical, and it includes
>>>support for getting a keystroke without requiring a user to press enter.
>>>
>>>As it happens, the C++ draft standard does not include such support.
>>
>>I've thought, for years, that this could be standardized, and I think
>>it would advance this discussion if you would describe the part of Ada
>>you referred to. (I don't know the Ada standard at all, btw).
>
>Well, perhaps it is simpler if I just quote it.
Thanks.
><various procedures and notes snipped>
These are basically the sorts of calls available in various C and C++
implementations. The notes seem to assume that the keyboard can
communicate in unbuffered mode with the CPU.
--
Mike Enright
menright@cts.com
http://www.users.cts.com/sd/m/menright/
Cardiff-by-the-Sea, California, USA
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "David M. Wheeler" <dwheeler@touchtechnology.com>
Date: 1997/10/01 Raw View
Dirk,
I'm sorry but you are incorrect. The function _getch() works on all
versions of Windows and DOS and Unix. It works in a raw mode, but it can
get single characters from the standard input stream. Sure keyboards
differ from platform to platform, but those differences are compensated
for by the standard C library (for which different versions exist for
each platform!)
Dave Wheeler
Touch Technology International
D Broer wrote:
>
> Min Xu wrote:
>
> > Is there a WAY to force cin.get or >> or any other methods (from stdio,
> > iostream..., anything STANDARD) to produce a key without requiring a user to
> > press enter??
> >
>
> The interface to a keyboard - or for that matter a terminal - be it a
> x-windows or ms-windows etc. is an implementation of the operating
> system. So no practical standard can exists. IMHO there might be some
> room for extending the stream classes to handle ioctl() as a standard -
> but that particular item is not portable either (seems to be UNIX
> only).
>
> Dirk
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: James Kuyper <kuyper@wizard.net>
Date: 1997/10/02 Raw View
David M. Wheeler wrote:
>
> Dirk,
> I'm sorry but you are incorrect. The function _getch() works on all
^
> versions of Windows and DOS and Unix. It works in a raw mode, but it can
Wrong. There is no _getch() on the Unix system I am working on right
now. _getch() is an implementation specific function, as you can tell
from the '_' at the start of its name. There is a getch() function here,
but it is part of the curses library, not the standard runtime library.
Even so, it isn't sufficient to get what Min Xu is asking for. On this
system, whether or not getch() waits for a newline depends upon the
setting of cbreak, which can only be changed using other implementation
specific functions.
It is nice to know that a wide variety of vendors chose to put a
function with the same (or similar) name in their libraries, and
hopefully it works the same way for each of them, but this doesn't meet
Min Xu's request for a STANDARD way to do this.
...
> D Broer wrote:
> >
> > Min Xu wrote:
> >
> > > Is there a WAY to force cin.get or >> or any other methods (from stdio,
> > > iostream..., anything STANDARD) to produce a key without requiring a user to
> > > press enter??
> > >
> >
> > The interface to a keyboard - or for that matter a terminal - be it a
> > x-windows or ms-windows etc. is an implementation of the operating
> > system. So no practical standard can exists. IMHO there might be some
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: min@linux.ls.wisc.edu (Min Xu)
Date: 1997/10/02 Raw View
In article <3432C46E.4000@touchtechnology.com>, "David M. Wheeler" wrote:
>Dirk,
>I'm sorry but you are incorrect. The function _getch() works on all
>versions of Windows and DOS and Unix. It works in a raw mode, but it can
>get single characters from the standard input stream. Sure keyboards
>differ from platform to platform, but those differences are compensated
>for by the standard C library (for which different versions exist for
>each platform!)
>
>Dave Wheeler
>Touch Technology International
>
I am sorry.... I don't follow this:
_getch() is a dos standard (just like getch()) function. NOT standard
C++... there is no such function defined in stdlib or stdio... If you are
thinking of conio.h, that's not part of un*x, at least the last time I
checked. _getch() is just the FAR version of getch(), and getch() is
defined in conio.h, which is used by Borland C++ on DOS Platform....
In all, which compiler on the unix are you using??
getch() will probably work for windows32/console programs, but not all
versions... hmm... it looks like there isn't a standard function after
all...
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: kanze@gabi-soft.fr (J. Kanze)
Date: 1997/10/03 Raw View
"David M. Wheeler" <dwheeler@touchtechnology.com> writes:
|> I'm sorry but you are incorrect. The function _getch() works on all
|> versions of Windows and DOS and Unix. It works in a raw mode, but it can
|> get single characters from the standard input stream. Sure keyboards
|> differ from platform to platform, but those differences are compensated
|> for by the standard C library (for which different versions exist for
|> each platform!)
Well, there is no _getch function on my Sun, at least not that I can
find. There is a getch function, but it is part of the curses library,
and works somewhat differently than the same function under DOS. In no
case is it part of the standard.
For that matter, the fact that a function is present under Windows, DOS
and Unix, even with the same meaning, doesn't mean that it is standard.
All of these OS's support the system calls open, read, write, and close,
with roughly the same semantics, but none of these functions are
standard C++ either.
--
James Kanze +33 (0)1 39 23 84 71 mailto: kanze@gabi-soft.fr
GABI Software, 22 rue Jacques-Lemercier, 78000 Versailles, France
I'm looking for a job -- Je recherche du travail
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: min@linux.ls.wisc.edu (Min Xu)
Date: 1997/09/30 Raw View
Is there a WAY to force cin.get or >> or any other methods (from stdio,
iostream..., anything STANDARD) to produce a key without requiring a user to
press enter??
I would like the code such as
void main() {
char c;
while (true) {
// some get character function here
cout << c;
}
}
to produce output like this:
aabbccddeeffgg // mixed input and output
instead of outputing like
abcdefg // user input
abcdefg // program output
thanks for any insight...
you would think this should be trivial and easy SINCE everycomputer has a
keyboard, and besides, reading a character DOES not require typeing
correctly anyway...
Things I have tried:
derive a childclass of istream, force the constructor to call
cin.rdbuf()->unbuffered(true);
initiate such a class before the while loop
derive a childclass of ifstrea, samething, except creating a ifstream from
FileDescriptor of 1 (stand out?) or create ifstream myin("/dev/tty",ios::in); //
on a linux system. then ask the childclass to call
myin.rdbuf()->unbuffered(true)
I even looked in iostream.h, streambuf.h and tried to do
cin.unsetf(ios::stdio); to force non-stdio behavior.
once again, thanks...
--
Min Xu
UW-Madison
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
mQCNAzLarkMAAAEEAKsulbaR7VViKfKHeDXYqABvrncrYE/8DzoICOmV6iDrNF6f
HN41bh/+WL/d/BVY4Di6nZYMR7cOZw8DiXKKyPOoYm2vXR1fVit70vP/7sq9m4Lu
IYAn88Y3TSVObi812Z0qnfjAkk6z3JrPbbYCZ+AP8k3PeAtO9iklgyrMAOhpAAUR
tB5NaW4gWHUgPG1pbkBsaW51eC5scy53aXNjLmVkdT4=
=41ze
-----END PGP PUBLIC KEY BLOCK-----
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: fjh@murlibobo.cs.mu.OZ.AU (Fergus Henderson)
Date: 1997/09/30 Raw View
D Broer <nospam@nospame.com> writes:
>Min Xu wrote:
>
>> Is there a WAY to force cin.get or >> or any other methods (from stdio,
>> iostream..., anything STANDARD) to produce a key without requiring a user to
>> press enter??
>
>The interface to a keyboard - or for that matter a terminal - be it a
>x-windows or ms-windows etc. is an implementation of the operating
>system. So no practical standard can exists.
That is false. The Ada standard is quite practical, and it includes
support for getting a keystroke without requiring a user to press enter.
As it happens, the C++ draft standard does not include such support.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: D Broer <nospam@nospame.com>
Date: 1997/09/30 Raw View
Min Xu wrote:
> Is there a WAY to force cin.get or >> or any other methods (from stdio,
> iostream..., anything STANDARD) to produce a key without requiring a user to
> press enter??
>
The interface to a keyboard - or for that matter a terminal - be it a
x-windows or ms-windows etc. is an implementation of the operating
system. So no practical standard can exists. IMHO there might be some
room for extending the stream classes to handle ioctl() as a standard -
but that particular item is not portable either (seems to be UNIX
only).
Dirk
--
To prevent automated e-mail from picking up my address (sorry it had to
come to this): 1) reply to !!Dirk.Broer@!!gsfc.nasa.gov (remove both
the !! from the name and the address) 2) If you are sending me a
solicitation - or any other form of advertisement that I haven't
specifically asked for, you will be charged a fee of $100 for me to
read it. In addition you will be liable for any collection expense I
have, including but no limited to tracking down who you are.
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: stephen.clamage_nospam@eng.sun.com (Steve Clamage)
Date: 1997/09/30 Raw View
On 30 Sep 97 06:45:05 GMT, min@linux.ls.wisc.edu (Min Xu) wrote:
>Is there a WAY to force cin.get or >> or any other methods (from stdio,
>iostream..., anything STANDARD) to produce a key without requiring a user to
>press enter??
This question is answered in considerable detail in the FAQ for
comp.lang.c, and in the book "C Programming FAQs" by Steve Summit,
Addison-Wesley, 1996.
The short answer is that it is an operating system issue, and is not
addressed in C or C++. There is no portable way to accomplish "raw"
character input, but on systems where it is possible, the compiler
manuals should tell you how to do it.
---
Steve Clamage, stephen.clamage_nospam@eng.sun.com
( Note: remove "_nospam" when replying )
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: min@linux.ls.wisc.edu (Min Xu)
Date: 1997/10/01 Raw View
In article <60rctl$5c0@mulga.cs.mu.OZ.AU>, Fergus Henderson wrote:
>>
>>The interface to a keyboard - or for that matter a terminal - be it a
>>x-windows or ms-windows etc. is an implementation of the operating
>>system. So no practical standard can exists.
>
>That is false. The Ada standard is quite practical, and it includes
>support for getting a keystroke without requiring a user to press enter.
>
>As it happens, the C++ draft standard does not include such support.
I didn't mean LITERALLY a scan code or a keyboard code, rather an ascii code
from the Operating system. The operating system is free to interpret all
the function codes for me... and I am perfectly happy at taking the ESC
sequence of function keys or having the OS hides those from me, but just a
get() function that behaves like ifstream.get(c); For what matters, cin is
a FILE, and should be able to read character by character.
In response to another reply, DOS also supports IOCTL if I
remembers, and you can set con: to uncooked mode (with an interrupt to ioctl
of couse, but the interrupt call can be embeded in a std C++ call)...
Maybe it is MORE common to inherit other ppl's include and #ifdefs
to accomplish this matter... (even though it's not standard).. If only it
is possible to set cin to uncooked mode WITHOUT depending on OS specific
calls...
Min Xu
UW-Madison
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.6.2
mQCNAzLarkMAAAEEAKsulbaR7VViKfKHeDXYqABvrncrYE/8DzoICOmV6iDrNF6f
HN41bh/+WL/d/BVY4Di6nZYMR7cOZw8DiXKKyPOoYm2vXR1fVit70vP/7sq9m4Lu
IYAn88Y3TSVObi812Z0qnfjAkk6z3JrPbbYCZ+AP8k3PeAtO9iklgyrMAOhpAAUR
tB5NaW4gWHUgPG1pbkBsaW51eC5scy53aXNjLmVkdT4=
=41ze
-----END PGP PUBLIC KEY BLOCK-----
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]