Sign in to follow this  

[Win32/C++] cin not pausing

This topic is 2665 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

I am using a console in a Win32 project. I attach myself to a console with the following (pulled from the net verbatim):

mI = GetStdHandle(STD_INPUT_HANDLE);
mO = GetStdHandle(STD_OUTPUT_HANDLE);
mE = GetStdHandle(STD_ERROR_HANDLE);

AllocConsole();
int hConsole = _open_osfhandle((long)mO, _O_TEXT);

// Set the buffer to be big enough to let us scroll text
COORD size = {80,500};
SetConsoleScreenBufferSize( mO, size );

// Redirect unbuffered data
*stderr =
*stdout = *_fdopen( hConsole, "w" );
*stdin = *_fdopen( hConsole, "r" );

setvbuf( stdout, 0, _IONBF, 0 );
setvbuf( stdin, 0, _IONBF, 0 );
setvbuf( stderr, 0, _IONBF, 0 );

// Make [w]cout, [w]cin, [w]cerr, [w]clog
// point to console.

std::ios::sync_with_stdio();


When I try to use [w]cin, the console does not pause and wait for input. It merrily skips right over without a second thought. Calling clear() and sync() beforehand made no difference.

How do I fix this?

Share this post


Link to post
Share on other sites

This topic is 2665 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