C2pp is a powerful tool that magically transforms your C code into modern C++ code. With an intuitive Streamlit interface, you can easily convert legacy C code to take advantage of C++ features and best practices.
C2pp intelligently converts:
- C-style includes to C++ equivalents (
stdio.h→iostream) - #define directives to const declarations
- structs to classes with proper methods
- printf/scanf to cout/cin
- malloc/free to new/delete
- And many other C constructs to their C++ counterparts
- Python 3.7 or higher
- pip (Python package installer)
-
Clone this repository:
git clone https://github.com/yourusername/c2pp.git cd c2pp -
Install the required dependencies:
pip install -r requirements.txt
Or install them directly:
pip install streamlit
-
Start the Streamlit app:
streamlit run app.py
-
The app will open in your default web browser.
-
Enter your C code in the left panel or use one of the provided examples.
-
Click the "✨ Cast Translation Spell ✨" button to transform your code.
-
View the translated C++ code in the right panel.
-
Download the translated code using the "📥 Capture Magic Code" button.
The translator analyzes your C code and performs the following transformations:
- Header Conversion: Changes C headers like
stdio.hto C++ equivalents likeiostream - Struct to Class: Converts C structs to C++ classes with methods
- Memory Management: Replaces
malloc/freewithnew/delete - I/O Operations: Converts
printf/scanftocout/cin - Constants: Transforms
#defineconstants to C++constdeclarations
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 100
struct Point {
int x;
int y;
};
void printPoint(struct Point *p) {
printf("Point: (%d, %d)\n", p->x, p->y);
}
int main() {
struct Point *p = (struct Point *)malloc(sizeof(struct Point));
p->x = 10;
p->y = 20;
printPoint(p);
free(p);
return 0;
}// C++ style includes
#include <algorithm>
#include <iostream>
#include <cstdlib>
// Using standard namespace
using namespace std;
// Constants (converted from #define)
const int MAX_SIZE = 100;
// Class converted from struct Point
class Point {
public:
int x;
int y;
// Constructor
Point() {}
// Methods
void printPoint();
};
// Method implementations for class Point
void Point::printPoint() {
cout << "Point: (" << this->x << ", " << this->y << ")" << endl;
}
// Main functions
int main(int argc, char* argv[]) {
Point *p = new Point;
p->x = 10;
p->y = 20;
p->printPoint();
delete p;
return 0;
}app.py- Streamlit web interfacec_cpp.py- Core translation enginerequirements.txt- Required Python packages
This project is licensed under the MIT License - see the LICENSE file for details.
- Streamlit for the amazing web app framework
- The C and C++ communities for their excellent documentation
Made with ❤️ by BIKRAM SARDAR, JAYDEEP DAS, ABHIRUP KARMAKAR