In DOS (or Windows), cls is an internal command of the command interpreter, so you cannot call it directly from a program. Normally, in a C/C++ program you can solve this problem by calling the command interpreter and having it call the command, e.g.: system("c:\windows\command.com /c cls");
I tried using exec() on this same string in Java, but it doesn't work, perhaps because Java launches a new hidden process or perhaps for some other reason. Anyway, that leaves two reasonable solutions. The first is to write your own little C/C++ program:
#include <conio.h>void main(){ clrscr();}
and run it with exec() instead. I tried this and it works fine.
The other solution is to make a native method that calls the same clrscr() function. That would consist of writing a java file something like this (exception handling omitted for brevity): public class ScreenClearer{ private native void ClearScreen(); static { System.loadLibrary("ScreenClearer"); } public static void main(String[] args) { ScreenClearer app = new ScreenClearer(); app.ClearScreen(); }}
Which you would then compile, as usual:
javac ScreenClearer.java
And then use javah to create the C/C++ header file:
javah -jni ScreenClearer
Now, you write your C/C++ file, including that generated header file, which would look like this: