I think the error is with double quotes:
system("\"java weka.classifiers.trees.J48 -t ML_data.arff -d training.model\"");
// ^^ ^^
This piece of code should instead be as follows:
system("java weka.classifiers.trees.J48 -t ML_data.arff -d training.model");
You appear to be using \"
in order to pass the double quotes into the system()
call, but that's excessive and causes an error. (The syntax for escaping a double quote is correct, but you don't need to pass the additional quotes to the system()
function.)
Here's a minimal test case to show what happens on Linux with the syntax you have used:
#include <cstdlib>
int main(void)
{
system("\"ls -l\"");
}
Output:
sh: ls -l: command not found
On the other hand, the code system("ls -l");
correctly calls ls -l
and displays the output in console.
Edit:
As far as your second error message goes:
Error: Could not find or load main class weka.classifiers.functions.Logistic
It's a very common problem: What does “Could not find or load main class” mean?. You need to set the classpath to point to weka.jar
in your system, for example, like so (change the exact path to the one in your distribution):
system("java -cp /usr/share/java/weka.jar weka.classifiers.trees.J48 -t ML_data.arff -d training.model");
or in the command line (note the use of the export
command here)
export CLASSPATH=/usr/share/java/weka.jar:$CLASSPATH
./name_of_your_cpp_executable_file
or put CLASSPATH
in your ~/.bashrc
:
CLASSPATH=/usr/share/java/weka.jar:$CLASSPATH
export CLASSPATH