π§ 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.cpp
cpp
Copy
Edit
int 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 Works
The CodeHint::commentFunction(std::istream&, std::ostream&) function reads your .cpp file line-by-line.
It uses pattern matching to detect:
Variable declarations
Print statements
Return values
Control structures (in future versions)
And then writes comments directly above each line.
Future versions will support more patterns and even AI-powered explanation generation.
πͺͺ License
MIT License
Feel free to use, modify, or contribute. See the LICENSE file.
π€ Contributing
Fork this repository
Make your changes
Submit a pull request
Ideas welcome for:
Better comment generation logic
A drag-and-drop GUI version
More language support (Python, Java, etc.)
π¨βπ» Author
Om Tirkhunde
π GitHub Profile https://github.com/OS0DEVELOPER