How to change the text in the console works

Possible duplicate:
How to remove the printed characters on the command line in C ++

My question is: how do I change the text at the time of launch of the console window in C ++. For instance.

If I reflect this.

cout<<"0%"; cout<<"25%"; cout<<50%"; cout<<75%"; cout<<"100%"; 

5 different words will be done. What if I want it to display 0%, and then 25%, thinking about creating a new word, IE replaced the current 0% with 25%. Is it possible? Thanks in advance.

+4
source share
1 answer

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.

+10
source

All Articles