Is it possible (if yes, how to) execute a string as code?

Is it possible to execute a string as code? Like for example, if the program asks the user to enter c++ code. The program can get the input as string, but is it possible to actually execute the code the user entered? If yes, how?
Not easily since C++ is meant to be compiled.
You have two ways of achieving this:
- Get the code, add what is needed to make it a compilable program, call a compiler, compile it, execute the output program
- Write a C++ interpreter ( or use an existing one )
Last edited on
Or, screw around with the assembly code that your compiler outputs. I'm sure you can enable reflectivity somehow.

-Albatross
You probably don't want them entering in C++ code, but you can embed a Python, JavaScript or Lua interpreter in a C++ program. Those can execute user-supplied code safely.

The documentation for embedding Google's V8 JavaScript engine is pretty easy to follow.

http://code.google.com/apis/v8/get_started.html
Topic archived. No new replies allowed.