.txt file into .cpp

#include <iostream>
#include <fstream>
#include <string>

int main() {
    // Open the input file (.txt)
    std::ifstream inputFile("input.txt");

    // Check if the file is open successfully
    if (!inputFile.is_open()) {
        std::cerr << "Error opening input file." << std::endl;
        return 1; // Return error code 1
    }

    // Create an output file (.cpp)
    std::ofstream outputFile("output.cpp");

    // Check if the output file is open successfully
    if (!outputFile.is_open()) {
        std::cerr << "Error opening output file." << std::endl;
        return 2; // Return error code 2
    }

    // Write necessary headers and starting code to the output file
    outputFile << "#include <iostream>\n\nint main() {\n";

    // Read each line from the input file and write it to the output file
    std::string line;
    while (std::getline(inputFile, line)) {
        // Add a comment prefix to each line
        outputFile << "    // " << line << '\n';
    }

    // Write the closing braces to complete the main function
    outputFile << "\n    return 0;\n}\n";

    // Close the input and output files
    inputFile.close();
    outputFile.close();

    return 0; // Return success code
}