My compiler says "not declared" |
This is fine in this case, but usually you should post the whole error message.
You need to include
<cstdlib>
.
<iostream>
doesn't contain the declaration of
system()
.
Since
system()
is part of the standard library, you can read the offline documentation for it by entering
man 3 system
at a terminal. Section 3 is the C library documentation. The manual page will tell you the header in which it is declared. It says "stdlib.h"; the C++ version of that header is named "cstdlib".
Edit:
Are you sure that you need to clear the screen? (Personally, I would be annoyed if a program wiped my terminal output.)
If yes, most Linux systems do not have a program named
cls
installed anyways, and there's no guarantee that it will clear the screen if it exists.
Try instead
int res = system("tput reset");
if you must do this.
Again, it makes assumptions that
tput
is installed, but that's more likely.