0

I was wondering how to clear the console in c++.

I tried:

cout << "\x1B[2J\x1B[H";

and

system("cls");

The first option seemed to work on my computer but it didn't work on my friend's computer. The second option worked but many people recommended me not to use it because of many reasons. There is also a third option which is to print lots of new lines but that method is janky. Are there any other solutions to this? I have tried searching for solutions on here but most posts are from 10 years ago.

  • `"\x1B[2J\x1B[H"` is an ANSI sequence so obviously you need a terminal that understands ANSI sequences to work. Modern conhost.exe and Windows Terminal are 2 of the working terminals. `system("cls");` runs `cls` in the default shell, so it's worse because it spawns a new shell and depends on the availability of a command named `cls` – phuclv Oct 25 '21 at 01:37

0 Answers0