how to open and print in a file in c++

#include <iostream>
#include <fstream>

int main() {
    std::ofstream outputFile("output.txt"); 
    if (outputFile.is_open()) {
        outputFile << "This is a line written to the file." << std::endl;
        outputFile << "Another line for the file." << std::endl;
        outputFile.close();
        std::cout << "File has been written successfully." << std::endl;
    } else {
        std::cout << "Unable to open the file." << std::endl;
    }
    return 0;
}