将C ++文件合并到一个源文件中 [英] Merge C++ files into a single source file
问题描述
我有一个带有多个源文件和多个头文件的c ++项目。我想将我的项目提交给需要单个源文件的编程竞赛。是否有一种自动方式将所有文件折叠成单个.cpp文件?
I have a c++ project with multiple source files and multiple header files. I want to submit my project for a programming contest which requires a single source file. Is there an automated way of collapsing all the files into single .cpp file?
例如,如果我有a.cpp,ah,b.cpp,bh等,我想获得一个main.cpp,它将编译并成功运行。如果我手动执行此操作,是否可以简单地合并头文件并将源文件相互附加?
For example if I had a.cpp, a.h, b.cpp, b.h etc., I want to get a main.cpp which will compile and run successfully. If I did this manually, could I simply merge the header files and append the source files to each other? Are there gotchas with externs, include dependencies and forward declarations?
推荐答案
在编码竞赛中,我也需要这样做。准确地说,Codingame。因此,我编写了一个快速的JavaScript脚本来实现此目的。您可以在这里找到它:
https://www.npmjs.com/package / codingame-cpp-merge
I also needed this for a coding contest. Codingame to be precise. So I wrote a quick JavaScript script to do the trick. You can find it here: https://www.npmjs.com/package/codingame-cpp-merge
我在1场现场比赛和一款离线游戏中使用了它,但从未产生过不良的结果。随时在github上提出更改建议或提出拉取请求!
I used it in 1 live contest and one offline game and it never produced bad results. Feel free to suggest changes or make pull requests for it on github!
这篇关于将C ++文件合并到一个源文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!