I want to know: how to clean screen on an UNIX-based system? I searched on the Internet, but I\'ve just found how to do it on Windows: system(\"CLS\") I don\'t want exactly
It is usually not a matter of just clearing the screen, but of making a terminal aware application.
You should use the ncurses library and read the NCURSES programming HowTo
(You could perhaps use some ANSI escape codes as David RF answered, but I don't think it is a good idea)
This code is for clear screen with reset scrollbar position in terminal style windows
#include <iostream>
int main(){
std::cout << "\033c";
return 0;
}
You can use the following code which use termcap for clear screen. (don't forget to link with the library)
#include <stdio.h>
#include <stdlib.h>
#include <termcap.h>
void clear_screen()
{
char buf[1024];
char *str;
tgetent(buf, getenv("TERM"));
str = tgetstr("cl", NULL);
fputs(str, stdout);
}
Maybe you can make use of escape codes
#include <stdio.h>
#define clear() printf("\033[H\033[J")
int main(void)
{
clear();
return 0;
}
But keep in mind that this method is not compatible with all terminals
Use system("clear");
with header #include <stdlib.h>
(for C Language) or #include <cstdlib>
(for C++).
#include <stdlib.h>
int main(void)
{
system("clear");
}