Kinda new to programming.
I found my self with this problem while programming a
tic tac toe like game in C++ but since it keeps printing the game table it quickly becomes a mess to read and understand.
Is there a way to clear the terminal with a command or function to put inside the code so it clears itself automatically?
I tried to mess with the settings but it just clear the terminal after the end of the code,
I also tried to find an already done function/instruction in vs code but with no luck.
I will be more then happy with just an external function in json.
2
Answers
VSCode terminal is a powershell console. Search for things like ‘powershell command for xxx’ with this in mind.
Quick search pointed me to
Clear-Host
command.I tried that in VSCode terminal, and yea, it cleared the screen.
You might want to read the whole article I found, as it tackles some additional issues regarding clearing the ‘screen’, you might need it for a clean ‘game screen’.
src: https://kgk.gr/2011/10/16/powershell-clrscr/
In Visual Studio you can use the
std::system()
function which executes a command into the terminalyou can execute the commands:
std::system("cls")
(for Windows)std::system("clear")
(for most Linux operating systems)this code should work also in Visual Studio code because it runs in the terminal in both.
example of usage