Sure! Here's a C++ program that reads lines from a file and displays them on the screen:

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

int main() {
    std::ifstream file("filename.txt"); // Replace "filename.txt" with the actual name of your file

    if (file.is_open()) {
        std::string line;
        while (std::getline(file, line)) {
            std::cout << line << std::endl;
        }
        file.close();
    } else {
        std::cout << "Unable to open file." << std::endl;
    }

    return 0;
}

To display the program itself on the screen, you can simply provide the name of the program file as the input file name. For example, if the program file is named "display_program.cpp", you would replace "filename.txt" with "display_program.cpp" in the code above

Write a c++program that reads lines from a file and displays them on the screen Enter the name of your program so that the program displays itself on the screen!

原文地址: https://www.cveoy.top/t/topic/hy5F 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录