Okay, I have been researching on how to do this, but say I am running a program that has a whole bit of output on the terminal, how would I clear the screen from within my program so that I can keep my program running?
I know I can just type clear
in terminal and it clears it fine, but like I said, for this program it would be more beneficial for me.
I found something that works, however, I'm not sure what it is or what it is doing.
cout << "\033[2J\033[1;1H";
That works but I have no clue what it is, if you could explain it, than I would much appreciate it.
To clear the screen in Visual C++, utilize the code: system("CLS"); The standard library header file <stdlib. h> is needed.
“cls” Means , clear screen. Every time this piece of code is processed whatever is written in your screen will get cleared and the remaining portion of code's output if any will be displayed.
A common way to do that is to use the `clear` command, or its keyboard shortcut CTRL+L.
For clearing the console in linux, we can use “clear” command. This will be passed inside the system() function.
These are ANSI escape codes. The first one (\033[2J
) clears the entire screen (J
) from top to bottom (2
). The second code (\033[1;1H
) positions the cursor at row 1
, column 1
.
All ANSI escapes begin with the sequence ESC[, have zero or more parameters delimited by ;, and end with a command letter (J and H in your case). \033
is the C-style octal sequence for the escape character.
See here for the full roadshow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With