如何在命令窗口的某个位置编写变量并在同一位置更新其值?

pea*_*man 2 c++ printing gcc

例如,输出是 a = 20我想将数字"20"更改为另一个数字并将结果写在第一个输出的相同位置,而不是在新行中(最早的"a"数量不需要只是最后的结果很重要)我尽量避免这样的事情:

输出:

a=20
a=21
a=70
.
.
.
Run Code Online (Sandbox Code Playgroud)

Dže*_*nan 6

你试过这个:

printf("\ra=%d",a);
// \r=carriage return, returns the cursor to the beginning of current line
Run Code Online (Sandbox Code Playgroud)