🧠 A header-only C++ library that automatically adds human-readable comments to your C++ code by analyzing line-by-line logic. Perfect for:
- Beginners who want help understanding code
- Teachers generating teaching materials
- Devs adding quick explanations to legacy code
- 📄 Auto-comments basic C++ logic: variables, loops, conditionals, returns
- ⚙️ Header-only: just include
CodeHint.hpp - 🧪 Simple demo app provided
- 🧰 Works with any C++17+ project
CodeHintPP/ ├── CodeHintLib/ │ └── include/ │ └── CodeHint.hpp # The header-only comment generator ├── CodeHintDemo/ │ ├── demo.cpp # Sample program using the library │ └── mycode.cpp # Sample input code to be commented ├── build/ # Will be created after build ├── LICENSE └── README.md
yaml Copy Edit
- CMake
- C++17 compiler (MSVC, g++, or clang++)
git clone https://github.com/OS0DEVELOPER/CodeHintPP.git
cd CodeHintPP
mkdir build &&cd build
cmake ..
cmake --build .
🚀 How to Run
Copy your .cpp file into the folder where the executable is:
bash
Copy
Edit
copy CodeHintDemo\mycode.cpp build\CodeHintDemo\Debug\
Run the tool:
bash
Copy
Edit
cd build\CodeHintDemo\Debug
CodeHintDemo.exe
Output:
You’ll get a file named mycode_commented.cpp with inline comments added automatically.
💡 Example Output
🔹 Original: mycode.cpp
cpp
Copy
Edit
int add(int a, int b) {
int sum = a + b;
std::cout <<sum << std::endl; return sum;}🔹 Generated: mycode_commented.cppcppCopyEditint add(int a, int b) { int sum = a + b; // Declare and initialize integer std::cout << sum << std::endl; // Print to console return sum; // Return the result}🧠 How It WorksThe CodeHint::commentFunction(std::istream&, std::ostream&) function reads your .cpp file line-by-line.It uses pattern matching to detect:Variable declarationsPrint statementsReturn valuesControl structures (in future versions)And then writes comments directly above each line.Future versions will support more patterns and even AI-powered explanation generation.🪪 LicenseMIT LicenseFeel free to use, modify, or contribute. See the LICENSE file.🤝 ContributingFork this repositoryMake your changesSubmit a pull requestIdeas welcome for:Better comment generation logicA drag-and-drop GUI versionMore language support (Python, Java, etc.)👨💻 AuthorOm Tirkhunde🔗 GitHub Profile https://github.com/OS0DEVELOPER