Created
January 12, 2021 11:00
-
-
Save bostrot/c59fde46896a9595582db13466840d17 to your computer and use it in GitHub Desktop.
This creates a nicely formatted markdown file from all the C++ source code (.cpp and .h) in a given project with multiple subprojects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <filesystem> | |
#include <string> | |
namespace fs = std::filesystem; | |
int main() { | |
std::ofstream out("./cpp_snippets.md"); | |
std::string current = ""; | |
for (auto& p : fs::recursive_directory_iterator("../")) { | |
if (p.is_regular_file() && | |
p.path().parent_path().string().length() >= 13 && | |
(p.path().extension() == ".cpp" || p.path().extension() == ".h")) | |
{ | |
std::string header = p.path().parent_path().string().substr(13); | |
if (current == header) { | |
header = ""; | |
} | |
else { | |
current = header; | |
header = "## " + header; | |
} | |
std::ifstream in(p.path()); | |
out << std::endl << header << std::endl << std::endl | |
<< "### " << p.path().filename() << std::endl << std::endl; | |
std::string line; | |
while (getline(in, line)) { | |
out << " " << line << std::endl; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment