Jump to content
  • Advertisement
Sign in to follow this  
zyrolasting

[Win32/C++] cin not pausing

This topic is 2881 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!