I want to clear the output of a C program produced with printf statements. I want to clear only one line, for example:
[source]
printf("AAAAAAAAAAAAAA\n");
printf("BBBBBBBBBBBBBB\n");
printf("CCCCCCCCCCCCCC\n");
printf("DDDDDDDDDDDDDD\n");
[terminal]
AAAAAAAAAAAAAA
BBBBBBBBBBBBBB
CCCCCCCCCCCCCC
DDDDDDDDDDDDDD
[I hope]
AAAAAAAAAAAAAA
BBBBBBBBBBBBBB
CCCCCCCCCCCCCC
I will "DDDDDDDDDDDDDD" line in write other string. I just want the above A, B, C sentences to left. Only clear D sentences to change the other sentences, unconditionally output D sentences.
How do I do this?
There're several ways to delete the DDDDDDDDDDDDDD
printf("\b");
printf("\r");
such as printf("\\033[8;5Hhello"); // Move to (8, 5) and output hello
printf("\\033[8;5Hhello"); // Move to (8, 5) and output hello
Other commands:
printf("\033[XA"); // Move up X lines;
printf("\033[XB"); // Move down X lines;
printf("\033[XC"); // Move right X column;
printf("\033[XD"); // Move left X column;
printf("\033[2J"); // Clear screen
...
It is the best ways to control the exact layout and format in a terminal
If you are using X-Term compatibles (Gnome Terminal included), then print the following
printf("\033[2J");
or
cout << "\033[2J";
where \\033
is the escape character in ASCII and [2J
is the specific action (clear).
I tried answering for what is best expected here.
printf("AAAAAAAAAAAAAA");
printf("BBBBBBBBBBBBBB");
printf("CCCCCCCCCCCCCC");
//printf("DDDDDDDDDDDDDD");
comment the last line or delete if you dont want to display in terminal. printf("xxxx") is the statement used for printing output in terminal.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.