objective:
executing a string of c(++) code with some kind of function comparable to the exec()
function in python.
example in python:
exec('print("hello world")')
#out:
#hello world
question:
is there a c++ version of exec in python?
objective:
executing a string of c(++) code with some kind of function comparable to the exec()
function in python.
example in python:
exec('print("hello world")')
#out:
#hello world
question:
is there a c++ version of exec in python?
#include <iostream>
int main(void) {
system("python -c \"print('hello world')\"");
return 0;
}
For system commands...?
but, is there a c++ version of exec in python?
you wan to execute C language statements from a string! so that is not possible with c.
why
because c is compiled language, the program first compiled and then executed. its possible in python as its interpreted language,means program is compiled by just-in-time compiler at runtime. hope this will help.
Well, technicall, you (maybe) can. But it's hardly a justifiable effort, there are other scripting languages that can be integrated in C++. For example Lua. Just to think about it, the following could work, if you have a method
int excuteCode(std::string code)
system
or OS-specific methods)userFunc
and execute it.