C ++ cannot do this - the compiled program does not know the syntax of the source language, identifier names, etc.
Even if you try to write a string to a file by calling the C ++ compiler to create a dynamic library and load and call, this call will not have any information about your program - it will not be able to refer to your variables, etc.
The most common reason to do this is to be able to evaluate expressions from strings. Writing code for this from scratch is definitely nontrivial, but depending on your specific requirements, you should find a library or an embedded scripting language to do something you need.
After a quick google, I found this - rather C than C ++, and I don't know how good it is. This is written as a demo of a parser generator that I have not heard of. You can find alternatives in the form of demos of more well-known parser generators such as yacc, bison, yacC ++ or antlr.
source share