Use cout << number << '\r' << flush
.
The '\r'
means "carriage return" (go to beginning of line", the flush
means "make sure what I've just printed reaches the output now. Normally output is only printed when a end of line is provided.
Edit: If you have a situation where the length of the output varies, e.g. counting down, you will have to pad the output with sufficient spaces to cover any extra output. For example cout << setw(3) << number ...
or cout << number << " " ...
would work.
Be aware, however, if your line gets longer than the width of the termina/command windo, it may become messy.