I did answer the question seriously.
From the link I posted:
What is Cling
Cling is an interactive C++ interpreter, built on the top of LLVM and Clang libraries. Its advantages over the standard interpreters are that it has command line prompt and uses just-in-time (JIT) compiler for compilation. Many of the developers (e.g. Mono in their project called CSharpRepl (link is external)) of such kind of software applications name them interactive compilers. |
Cling is an interpreter for C++ code. It does what you want.
Edit:
Probably I should elaborate more.
What you want to write is an "interpreter". An interpreter executes code as it is read.
C++ was not designed to be interpreted, and because of some technical reasons, writing an interpreter for it (from scratch) will be extremely difficult. Projects that do try to interpret it, like Cling, leverage a large and well-known compiler infrastructure named LLVM to compile and run your code as you type it in.
You should consider interpreting another language, one designed to be interpreted, or at least with that capability built-in or included standard, such as Lua, like I said above.
Or, if you're feeling ambitious, you can write your own domain-specific language and design, parse, and interpret a language of your choosing. Tools like
yacc
and
lex
might help you do that.