How do you clear the screen being in a file

Hi all of you. I find no keyword for that. Someones use: system("cls"); But my compiler ignores that. Thanks in advance
I doubt that your compiler 'ignores' it - either it will give an error or it will run.

If you are running from the Windows command window then it will clear the current command window.

You may/should need
#include <iostream>
in the header in order to use system().
lastchance wrote:
You may/should need
#include <iostream>

Not <iostream>, <cstdlib>.

Also, when it comes to debugging, assume that all issues are your fault, until and unless you can prove otherwise. I highly doubt that your compiler is silently ignoring your source code.

Especially when it comes to compiler bugs, if you're complaining that the compiler's behavior is wrong, you better be damn sure you're right (i.e., you have irrefutable proof of incorrect behavior and a patch) before you waste people's time.
Last edited on
Thanks. <iostream> is included. My compiler is g++. I use Linux 16.04. My compiler says "not declared"
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.
Last edited on
Hurrah. Problem solved. A chace you are here. But C++ is really very hard ! Thanks again.
Cheers mbozzi - too many late nights for me; I intended to write cstdlib but my brain wasn't quite in gear. Glad the problem is sorted.
Topic archived. No new replies allowed.