I think the shorter way would be something like this: while(true) cout << (GetAsyncKeyState(VK_DOWN)||GetAsyncKeyState(VK_UP)?"hello!":" ") << "\b\b\b\b\b\b";
(windows.h required) GetAsyncKeyState returns 0 if the given key is up, non-zero when it is down
VK_DOWN, VK_UP are maros for key
"\b\b\b\b\b\b" puts the cursor back (each '\b' is a step)
For this you should better use SetConsoleCursorPosition