how to ignore the [enter] key?

Discussion in 'C++' started by aguai, Apr 22, 2007.

  1. aguai

    aguai Guest

    hi Im trying to do is something should be simple:
    I wish to ignore the [enter] key....'\n'
    my test is Like this

    /*di.cpp*/
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    int main(void)
    {
    setvbuf(stdin, NULL, _IONBF, 0);
    while ( cin.peek()!='\n'){cout.put(cin.get())<<endl;}
    return 0;

    }

    then I try
    aguai@home:~/cpp$ ./a.out
    please dont...
    p
    l
    e
    a
    s
    e

    d
    o
    n
    t
    ..
    ..
    ..

    but what i hope is like
    aguai@home:~/cpp$ ./a.out
    p
    l
    e
    a
    s
    e

    d
    o
    n
    t
    ..
    ..
    ..
    <push enter and exit....>

    is that possible to be done with a ansi C/C++ function?
    thanx
     
    aguai, Apr 22, 2007
    #1
    1. Advertising

  2. aguai

    Colander Guest

    On Apr 22, 5:15 pm, aguai <> wrote:
    > hi Im trying to do is something should be simple:
    > I wish to ignore the [enter] key....'\n'
    > my test is Like this
    >
    > /*di.cpp*/
    > #include <cstdio>
    > #include <cstdlib>
    > #include <iostream>
    > using namespace std;
    > int main(void)
    > {
    > setvbuf(stdin, NULL, _IONBF, 0);
    > while ( cin.peek()!='\n'){cout.put(cin.get())<<endl;}
    > return 0;
    >
    > }
    >
    > then I try
    > aguai@home:~/cpp$ ./a.out
    > please dont...
    > p
    > l
    > e
    > a
    > s
    > e
    >
    > d
    > o
    > n
    > t
    > .
    > .
    > .
    >
    > but what i hope is like
    > aguai@home:~/cpp$ ./a.out
    > p
    > l
    > e
    > a
    > s
    > e
    >
    > d
    > o
    > n
    > t
    > .
    > .
    > .
    > <push enter and exit....>
    >
    > is that possible to be done with a ansi C/C++ function?
    > thanx


    (Deleted follow-ups)

    I believe you are searching for 'noecho' which is in curses.h
     
    Colander, Apr 22, 2007
    #2
    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. Lars Netzel

    Need to ignore Enter key in Form

    Lars Netzel, Mar 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    4,479
    masoud bayan
    Mar 2, 2005
  2. BrianDH

    Enter Key H*ll, control enter key submit button

    BrianDH, Jan 12, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    438
    Anders Matthiessen
    Jan 12, 2005
  3. M P
    Replies:
    1
    Views:
    543
  4. Matt
    Replies:
    1
    Views:
    560
    Michael Winter
    Mar 6, 2004
  5. HopfZ
    Replies:
    0
    Views:
    624
    HopfZ
    Aug 28, 2006
Loading...

Share This Page