You are here:

C++/Reading from Standard Input

Advertisement


Question
Hi,

I am trying to read from the standard input.
Right now the user should enter a character and
then press Enter.

I was wondering if it's possible to read from
terminal without requiring the user to press
Enter. For example, I'm asking the user a yes/no
question. I want the user to be able to only
press y or n and not have to press Enter
afterwards.


Thanks for your help,
Adrien  

Answer
Hello Adrien, thank you for the question.

I believe that you should take a look at the function getch(), which simply waits for a key to be pressed to exit. This would give you the functionality that you describe. A lot of people typically use this function for a press any key... type of deal, where you simply want to pause at the end of an application until the user hits a key. You can find excellent documentation on this function in the MSDN library, which you can use for free at www.msdn.microsoft.com

I hope this information was helpful.

- Eddie

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Eddie

Expertise

I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.

Experience

I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.