Skip to main content
GameDev.net gamedev.net
🔒 Locked

cin.get()

Started by MrPoopypants Dec 9, 2002 at 6:17 PM 1 replies 250+ views
Original Post
MrPoopypants
MrPoopypants
(C++ using iostream.h library) How do i use cin.get to read only the first char entered. For example: Hit any key to continue (Q to quit) > and it will immediately read the char entered without the user hitting enter. I tried googleing but that didnt really answer my question. If anyone could help me id really appreciate it Thanks [edited by - MrPoopypants on December 9, 2002 7:24:34 PM]
(0110101101000110)The Murphy Philosophy: Smile . . . tomorrow will be worse.
Ecliptici
Ecliptici
I would use:

printf("Hit any key to continue (''Q'' to quit)");
while(!kbhit());
char c = getch();
if(c == ''q'' || c == ''Q'')
//...
else
//...
Oluseyi
Oluseyi
cin.get( c, INT_MAX, ''\n'' ); 

OR
cin >> c; 

get won''t block if there is any data in the input buffer, and returns immediately there is in the no-parameter version, which is why you use the delimiter-specified version above.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.