C ++ Change the output with "cout"

Is it possible to change text printed with cout? I would like it to show the current percentage of something, without having to have a new row for each percent. Is it possible?

+5
source share
3 answers

This works for me:

std::cout << "1111";
std::cout << "\r";
std::cout << "2222";

\r- carriage return symbol. Puts the "cursor" back to the beginning of the line.

Alternatively, you can use the symbol \b. This is backspace. When printing, one character is returned.

+11
source

, . (, cout . "" ?) cout - , , , . , , . - , , , cout .

+1

One thing you definitely won't get from cout is the length of the end line. Since this can be changed, you can use lines that are too long, which (using '\ r') will cause new lines to be printed with each update. If you want to use a specific platform, use platform-specific functions to get the size of the terminal (remember that you cannot connect to any terminal at all, for example, redirected to a file).

0
source

All Articles