freopen c++

#include <iostream>
#include <fstream>

int main() {
    // Step 1: Declare a file pointer variable
    FILE *filePointer;

    // Step 2: Open the file in write mode ("w")
    filePointer = freopen("example.txt", "w", stdout);

    // Step 3: Check if the file is opened successfully
    if (filePointer == NULL) {
        perror("Error opening the file");
        return -1;
    }

    // Step 4: Print content to the file using standard output functions
    std::cout << "This content will be written to the file." << std::endl;

    // Step 5: Close the file
    fclose(filePointer);

    // Step 6: Revert standard output to the console
    freopen("CON", "w", stdout);

    // Step 7: Confirm the change in standard output
    std::cout << "This content will be displayed on the console." << std::endl;

    return 0;
}