• Advertisement
Sign in to follow this  

[Win32/C++] cin not pausing

This topic is 2756 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);
mE = GetStdHandle(STD_ERROR_HANDLE);

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.


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
Sign in to follow this  

  • Advertisement