c++ how to read from a file

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

int main() {
    std::ifstream inputFile("example.txt"); // Step 1: Create an input file stream and open the file

    if (inputFile.is_open()) { // Step 2: Check if the file is successfully opened
        std::string line;

        while (std::getline(inputFile, line)) { // Step 3: Read the file line by line
            std::cout << line << std::endl; // Step 4: Process or display the read data
        }

        inputFile.close(); // Step 5: Close the file after reading
    } else {
        std::cerr << "Error opening the file." << std::endl; // Step 2a: Handle the case where the file could not be opened
    }

    return 0;
}