c++ lettura file

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

int main() {
    // Step 1: Declare variables
    std::ifstream inputFile;
    std::string fileName, line;

    // Step 2: Get file name from user
    std::cout << "Enter the name of the file: ";
    std::cin >> fileName;

    // Step 3: Open the file
    inputFile.open(fileName);

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

    // Step 5: Read and display the contents of the file line by line
    while (getline(inputFile, line)) {
        std::cout << line << std::endl;
    }

    // Step 6: Close the file
    inputFile.close();

    return 0;
}