get one character from input at a time?

Discussion in 'C++' started by Chris, Apr 1, 2006.

  1. Chris

    Chris Guest

    I want to find a way to get one character from input and end the stream
    without pressing return.
    Is there a way to do this?

    Thanks for any help!
    -Chris
    Chris, Apr 1, 2006
    #1
    1. Advertising

  2. Chris

    Phlip Guest

    Chris wrote:

    > I want to find a way to get one character from input and end the stream
    > without pressing return.
    > Is there a way to do this?


    There are allegedly several ways to do that with <iostream>.

    I would just call getche() and be done with it, because I wouldn't use
    iostream for formatted input.

    --
    Phlip
    http://www.greencheese.org/ZeekLand <-- NOT a blog!!!
    Phlip, Apr 1, 2006
    #2
    1. Advertising

  3. Chris

    Daniel T. Guest

    In article <%KnXf.1092$>,
    "Phlip" <> wrote:

    > Chris wrote:
    >
    > > I want to find a way to get one character from input and end the stream
    > > without pressing return.
    > > Is there a way to do this?

    >
    > There are allegedly several ways to do that with <iostream>.


    Are there? I don't think so. I think the only way to do what the OP
    wants is with a non-standard library. I could be wrong though... Anybody?


    --
    Magic depends on tradition and belief. It does not welcome observation,
    nor does it profit by experiment. On the other hand, science is based
    on experience; it is open to correction by observation and experiment.
    Daniel T., Apr 1, 2006
    #3
  4. * Daniel T.:
    > In article <%KnXf.1092$>,
    > "Phlip" <> wrote:
    >
    >> Chris wrote:
    >>
    >>> I want to find a way to get one character from input and end the stream
    >>> without pressing return.
    >>> Is there a way to do this?

    >> There are allegedly several ways to do that with <iostream>.

    >
    > Are there? I don't think so. I think the only way to do what the OP
    > wants is with a non-standard library. I could be wrong though... Anybody?


    There is a way to read unbuffered on /some/ systems, but like most of
    iostreams it's not guaranteed to work, so is very much less than useful.

    I absolutely don't feel like digging up the details.

    Someone?

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
    Alf P. Steinbach, Apr 1, 2006
    #4
  5. Chris

    Guest

    Alf P. Steinbach wrote:
    > * Daniel T.:
    > > In article <%KnXf.1092$>,
    > > "Phlip" <> wrote:
    > >
    > >> Chris wrote:
    > >>
    > >>> I want to find a way to get one character from input and end the stream
    > >>> without pressing return.
    > >>> Is there a way to do this?
    > >> There are allegedly several ways to do that with <iostream>.

    > >
    > > Are there? I don't think so. I think the only way to do what the OP
    > > wants is with a non-standard library. I could be wrong though... Anybody?

    >
    > There is a way to read unbuffered on /some/ systems, but like most of
    > iostreams it's not guaranteed to work, so is very much less than useful.
    >
    > I absolutely don't feel like digging up the details.
    >
    > Someone?


    Isnt the answer that the standard stream are synchronous, whereas the
    OP would need an asynchronous stream and then poll it for input?

    OTOH what we are looking at is an input event?... as part of an event
    driven system, commonly (though not exclusiveley) the domain of a GUI,
    for which lamentably there is no standard C++ Library, though such GUI
    would be a great addition to the standard libraries!


    regards
    Andy Little
    , Apr 1, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leif K-Brooks

    Read one character of input?

    Leif K-Brooks, Dec 10, 2003, in forum: Perl
    Replies:
    2
    Views:
    641
    Alex Zeng
    Dec 11, 2003
  2. Tim Tyler
    Replies:
    1
    Views:
    1,132
    Tom McGlynn
    Jun 27, 2003
  3. flamesrock
    Replies:
    8
    Views:
    433
    Hendrik van Rooyen
    Nov 24, 2006
  4. George2
    Replies:
    2
    Views:
    364
    James Kanze
    Jan 25, 2008
  5. Tena
    Replies:
    3
    Views:
    160
    Martijn Lievaart
    Nov 6, 2007
Loading...

Share This Page