Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Press any key to continue ??

Status
Not open for further replies.

Heals

Programmer
Oct 1, 2002
3
AU
I need to read the instance of a keypress from the keyboard in linux or unix. I have used getchar() for the dos based compilers but I cannot find an eqivalent for the g++ compiler.

Is there such a function or do I have to construct my own. If so how is this done?
 
The easy way is to say 'Press return to continue'. getchar is buffered and is waiting for a CR before you get anything. The difficult way is to play with ioctl. There are so many options with ioctl, I wouldn't know how to advise you on it. If you call

ioctl( 0, FIONREAD, &numAvailable)

numAvailable will tell you how many chars have been pressed.
 
A getline should work, although a lot of compilers even getline won't read untill the enter is pressed.

Code:
string trash;
getline(cin, trash, 1);

Goodluck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top