You cannot do the way you dream, at least not in standard C++11 (using only standardized C++11 functions). You practically need some operating system support, and you implicitly want some event loop (or use some multi-threading approach).
However, you could use your operating system facilities and/or some external libraries.
FWIW, Linux has multiplexing syscalls such as poll(2) (and I am sure that Windows, Android, MacOSX, .... have similar things); but you'll much better use libraries like ncurses or Qt or SFML (see also POCO framework).
Details are considerably more complex than what you imagine, and are operating system specific (but some libraries are frameworks working on several operating systems). See also this & that answers and read the tty demystified page. Be aware that "terminal" is usually today some abstract virtual device, but in the past have been a complex device (which is mostly emulated today).
And don't forget that cin
might be something else than a terminal. It might be (on POSIX systems notably) a pipe(7) (command pipeline) or a file (redirection). Then waiting for 5 seconds might be meaningless or useless.