Skip to content
← Back to Community
How to clear screen in repl.it C++
Profile icon
SpartanDoge

I need a function that can clear my console screen on this website. I do know the method of printing 50 lines, but that is not what I am looking for.

Answered by Geocube101 [earned 5 cycles]
View Answer
Voters
Profile icon
EricLi28
Profile icon
GabrielSousa2
Profile icon
SpartanDoge
Comments
hotnewtop
Profile icon
Geocube101

Here

void clear() { std::cout << "\033[2J\033[1;1H"; }
Profile icon
SpartanDoge

@Geocube101
Thank you, it worked.

Profile icon
SPQR

void moveCursor(int x, int y)
{
std::cout << "\033[" << y << ";" << x << "H";
}
calling this function with the parameters 0,0 would move your cursor back to the top left of the console window, allowing you to overwrite all your stuff with new stuff. Useful if you want to avoid that flicker you get from the other thing.