Use cout << number << '\r' << flush .
'\r' stands for "carriage return" (go to the beginning of the line), flush means "make sure that what I have just published, is now reaching the output. Usually the output is displayed only when the end of the given line.
Edit: if you have a situation where the output length is changed, for example. in counting, you will miss the conclusion with enough spaces to cover any additional output. For example, cout << setw(3) << number ... or cout << number << " " ... will work.
Remember, though, if your line gets longer than the width of the wind termina / command terminal, it can become messy.
source share