c++ - 如何以编程方式检查源编译?

标签 c++

有一些带代码的字符串:

std::string code = "int main(){return 0;}"

我可以使用什么工具来检查这是否是有效的 C++ 代码?类似于

checker.checkCPPcode(code) which returns bool

会很好。

最佳答案

g++ 这样的 C++ 编译器可以完成这项工作。将字符串写入临时文件,对该文件运行 g++ -fsyntax-only,然后对返回值进行操作。

关于c++ - 如何以编程方式检查源编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741294/

相关文章:

c++ - 为什么不调用成员变量的移动构造函数?

c++ - 在 xcode 中配置 freeimage

c++ - C++ 中的析构函数和类 [内存泄漏]

c++ - 为什么 T* 可以在寄存器中传递,但 unique_ptr<T> 却不能?

c++ - 异常 : Deletion of node in Binary Search Tree

c++ - 在 bash 中捕获线程转储

c++ - 程序在 VS 2013 中有效,但在 .exe 中无效

c++ - OpenGL - 使用 glReadPixels 读取深度分量返回不正确的值

c++ - 为 C++ 构建 nana 时出现 "make"错误

c++ - C++ 跨平台编程