Sign in to follow this  

Quick question

This topic is 4397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster

void pressEnter()
{
char input = 0;
do
{
while(!_kbhit());
input = _getch();

if(input == 0)
input = _getch();
}
while(input != 13); // is 13 enter?
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Sabonis
hi Dave,
I tried your solution but it doesnt work unless you enter and character or number and then hit enter.... I need it to work if just the enter key is hit


Oh poo, sry. Early morning here.

Share this post


Link to post
Share on other sites
That should be fine. When I was using linux, I always used 'getchar', but it shouldn't matter.


while( std::cin.get() != '\n' );


Although, you might want to check if there is something in the file stream already.


if( /* input still in the stream from previous user input */ )
while( std::cin.get() != '\n' );

cout << "Press any key to continue." << endl;

while( std::cin.get() != '\n' );


Or, the second one might not be suitable for your program.

Share this post


Link to post
Share on other sites

This topic is 4397 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this