[Win32/C++] cin not pausing

Started by
-1 comments, last by zyrolasting 13 years, 7 months ago
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 textCOORD 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?

This topic is closed to new replies.

Advertisement