For a windows solution, you could try this which will allow the user to press any key to continue (not just enter):
void Pause(char *message = "Press any key to continue . . . ") {
std::cout << message;
HANDLE hStdin;
DWORD cNumRead;
INPUT_RECORD irInBuf[1];
if ( HANDLE(hStdin = GetStdHandle( STD_INPUT_HANDLE )) == INVALID_HANDLE_VALUE )
return;
while ( true ) {
if (! ReadConsoleInput( hStdin, irInBuf, 1, &cNumRead) )
return;
for (DWORD i = 0; i < cNumRead; ++i)
if ( irInBuf[i].EventType == KEY_EVENT && irInBuf[i].Event.KeyEvent.bKeyDown ) {
std::cout << '\n';
return;
}
}
}
To remove the message, simply call it like this.
Pause("");