AFAIK it can be done with readline or ncurses libraries, plain C++ won't do what you require.