c++ rewrite file

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

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

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

    // Open the output file in write mode
    std::ofstream outputFile("output.txt");

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

    // Read each line from the input file
    std::string line;
    while (std::getline(inputFile, line)) {
        // Write the line to the output file
        outputFile << line << std::endl;
    }

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

    return 0;
}