Executing a program from a string variable.

This is convenient if you want to generate an algorithm of program actions during execution.

Calling:

double iret = run_cpp("run_from_variable",strint programtext,int arg1,double arg2,string arg3);


Here:

programtext - program text to execute.

arg1, arg2 и arg3 - arguments with which the program will be executed (in it you can consider them with the get_args function)

Example.

Form the text of the program and execute it with parameters 100, 111.1 and "text argument". Show the result of the program execution in the message window.


string programtext = "int main(){ cout << \"My programm \"<<\"\n\";  int iarg1; double darg2; string sarg3; run_cpp(\"get_args\",iarg1, darg2, sarg3);";

programtext += "cout << iarg1 << \" ,\" << darg2 << \" ,\" << sarg3; return -1;}";

int iret = run_cpp("run_from_variable", programtext, 100, 111.1, "text argument");

cout << "iret = " << iret << "\n";



We have generated the program in such a way that, upon completion, it executes the return -1 function.

So iret will contain -1.