阅读包含代码和文件的文件执行它 [英] reading a file containing code & executing it

查看:86
本文介绍了阅读包含代码和文件的文件执行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个visual basic程序,并不确定采取以下方法:I创建了一个神经网络(好几个选项)但是对于预处理,我希望用户能够通过输入c ++代码,自由地指定他们如何做(如果他们希望通用选项)。



我想的只是一个大文本框,然后将其写入文件......然后读取&执行。我找到了这样做的参考,但不明白怎么做。如果您能解释/知道类似主题的链接或看到更好的选择,我会非常感激!即使有一个更简单的选项,我也很好奇如何将文件作为代码阅读。



非常感谢!

推荐答案

问题在于你必须在你的应用程序中使用编译器(和链接器),因为在非托管C ++的情况下,你不能保证有一个编译器在系统中,忘记找到这个编译器及其调用的问题。我不认为你真的想要处理它,除非你想使用一些编译器及其源代码,所以你可以将它嵌入你的应用程序中。



使用.NET,故事非常不同,因为C#和VB.NET编译器总是与可再发行的.NET Framework绑定并且始终可用(但不是C ++!)。然后通过CodeDOM(和应用程序域,这是问题的模式困难部分)解决问题。如果你有兴趣,我可以给你一些链接。







感谢您的澄清。请查看我过去的答案:

使用CodeDom生成代码 [ ^ ],

创建使用可重新加载插件的WPF应用程序...... [ ^ ]。



我过去的答案中解释了一些更高级的问题:

创建使用可重新加载插件的WPF应用程序...... [ ^ ],

AppDomain拒绝加载程序集 [ ^ ],

动态加载用户控件 [ ^ ],

C#Reflection InvokeMember on existing instance [ ^ ],

通过它的字符串表示从汇编中收集类型 [ ^ ]。< br $> b $ b

-SA
The problem is just that you have to have the compiler (and linker) with your application, because, in case of unmanaged C++, you cannot guarantee there is a compiler in the system, forget about the problem of finding this compiler and its invocation. I don''t think you really want to deal with that, unless you want to use some compiler with its source code, so you could embed it in your application.

With .NET, the story is very different, as C# and VB.NET compilers are always bound with the redistributable .NET Framework and are always available (but not C++!). Then the problem is solved via CodeDOM (and Application Domains, which is mode difficult part of the problem). If you are interested, I can give you some links.



Thank you for clarification. Please see my past answers:
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^].

Some more advanced issues are explained in my past answers:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
Dynamically Load User Controls[^],
C# Reflection InvokeMember on existing instance[^],
Gathering types from assemblies by it''s string representation[^].

—SA


一个选项是使用CINT [ ^ ]。



Root [ ^ ]也有一些您可能会觉得有用的功能。



你必须使用P / Invoke或C ++ / CLI与CINT接口,但你可以直接执行C ++代码。



最好的问候

Espen Harlinn
One option would be to use CINT[^].

Root[^] also have several features you may find useful.

You''ll have to use P/Invoke or C++/CLI to interface with CINT, but you will be able to execute C++ code directly.

Best regards
Espen Harlinn


这篇关于阅读包含代码和文件的文件执行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆