Re: cin >> c
From: K Campbell (kieran_at_cyrocom.co.uk)
Date: 08/24/04
- Next message: kanze_at_gabi-soft.fr: "Re: <string> to lowercase"
- Previous message: Ronald Landheer-Cieslak: "Re: access private member function"
- In reply to: Kevin W.: "cin >> c"
- Next in thread: Mike Wahler: "Re: cin >> c"
- Reply: Mike Wahler: "Re: cin >> c"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 24 Aug 2004 12:08:59 -0700
Try doing this:
char c;
cin>>c;
cin.ignore();
cin.getline(name, int);
or, if you want to just capture one character, without the user having
to press enter:
(you must #include <conio.h>)
char c = getch();
cin.getline(name, int);
Hope i've been of some help.
Kieran
"Kevin W." <contact@in.sig> wrote in message news:<opsc6ef3ufjxvii7@localhost.localdomain>...
> I'm writing a simple Unix console app. I need to take an input of a
> single character from the user and discard the rest.
>
> If I have:
> char c;
> cin >> c;
> And the user types the letter 'a', then presses Enter, 'a' gets put into c
> as I want. BUT, Enter remains as the next character in the stream, so if
> I then do a getline(cin, word), I get an empty string in word. The other
> requirement I need is that if the user just presses Enter without entering
> a letter, c should be assigned to '\n'.
>
> Ideally, it should process the character (whatever it is) without the user
> having to press Enter.
- Next message: kanze_at_gabi-soft.fr: "Re: <string> to lowercase"
- Previous message: Ronald Landheer-Cieslak: "Re: access private member function"
- In reply to: Kevin W.: "cin >> c"
- Next in thread: Mike Wahler: "Re: cin >> c"
- Reply: Mike Wahler: "Re: cin >> c"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|