有谁知道如何在程序已经运行时编译您编写的 c++ 代码?
后来我想运行该代码。
我想这样做是因为我正在尝试制作一款可以教您编程的游戏,因此用户必须在游戏运行时编写代码并对其进行测试。
谢谢你的帮助
有谁知道如何在程序已经运行时编译您编写的 c++ 代码?
后来我想运行该代码。
我想这样做是因为我正在尝试制作一款可以教您编程的游戏,因此用户必须在游戏运行时编写代码并对其进行测试。
谢谢你的帮助
You'd have an easier time if you chose a language that was designed with embedding in mind - like LUA or python. For C++, you'd have to go for something extremely clumsy and fragile like invoking an external compiler (which is also a logistics nightmare when shipping your game), or something as complex as integrating a compiler in your game (probably doable with llvm components, but...)
Also, for "teaching programming", C++ probably isn't the best language :)
您必须调用编译器来编译和链接用户输入的代码。必须将其制成可执行文件,然后从您创建的另一个进程运行,或者作为动态加载和调用的库。
这在 POSIX 平台(如 Linux 和 OSX)和 Windows 上是不同的。