c to c++ converter online

Step 1: Include Necessary Headers in C++ Format

#include <iostream>
using namespace std;

Step 2: Replace printf and scanf with cout and cin

// C
printf("Hello, World!\n");
int num;
scanf("%d", &num);

// C++
cout << "Hello, World!" << endl;
int num;
cin >> num;

Step 3: Replace C-Style Arrays with C++ Vectors

// C
int arr[5] = {1, 2, 3, 4, 5};

// C++
#include <vector>
vector<int> vec = {1, 2, 3, 4, 5};

Step 4: Replace struct with class

// C
struct Point {
    int x;
    int y;
};

// C++
class Point {
public:
    int x;
    int y;
};

Step 5: Replace malloc and free with new and delete

// C
int arr = (int )malloc(5 * sizeof(int));
free(arr);

// C++
int *arr = new int[5];
delete[] arr;

Step 6: Use string Class Instead of Character Arrays for Strings

// C
char str[] = "Hello, World!";

// C++
#include <string>
string str = "Hello, World!";

Step 7: Replace C-Style Function Declaration with C++ Function Declaration

// C
int add(int a, int b);

// C++
int add(int a, int b);

Step 8: Replace #define with const for Constants

// C
#define PI 3.14

// C++
const double PI = 3.14;

Step 9: Update Header Files to C++ Standard

// C
#include <stdio.h>

// C++
#include <cstdio>

Step 10: Modify Main Function Signature

// C
int main() {
    // code
    return 0;
}

// C++
int main() {
    // code
    return 0;
}