Skip to content
← Back to Community
I want to use clear screen function in my c++ code on repl
Profile icon
RishuMishra

As repl provides ubuntu compiler for c++, I don't know how to use clear screen function and which header file will be used for that function. kindly guide me.

Answered by theangryepicbanana [earned 5 cycles]
View Answer
Voters
Profile icon
binwiz
Profile icon
PaulZbarcea
Profile icon
MichelProgamer
Profile icon
FrogDude69
Profile icon
Mapacherino
Profile icon
pgupta1808
Profile icon
cs1bsummer
Profile icon
SiyungCho1
Profile icon
DiegoPuerta1
Profile icon
AlexWeller
Comments
hotnewtop
Profile icon
theangryepicbanana

just do

cout << "\033[2J\033[0;0H";
Profile icon
RishuMishra

@theangryepicbanana It worked!!! Thanks a lot. By the way, I wanna know what that line means and how it is functioning.

Profile icon
SPQR

@RishuMishra https://en.wikipedia.org/wiki/ANSI_escape_code
Outputting certain codes to some terminals (including the one repl.it uses) can do specific things to the terminal depending on the code.
The \033[2J clears the screen and resets the cursor and the \033[0;0H moves the cursor to 0,0 (again)
You can change the 0;0 to Y;X to move the cursor to line Y and column X thus allowing you to overwrite only certain portions of your screen. Handy for games and such.

Profile icon
theangryepicbanana

@SPQR great explanation. +1

Profile icon
theangryepicbanana

@SPQR great explanation. +1

Profile icon
pgupta1808

thank you this works !! @theangryepicbanana

Profile icon
pgupta1808

nice explanation thnx @SPQR