#include <iostream>
      #include <fstream>
      #include <string>
      using namespace std;
      int readFile () {
        // Create a text string, which is used to output the text file
        string myText;
        // Read from the text file
        ifstream MyReadFile("filename.txt");
        // Use a while loop together with the getline() function to read the file line by line
        while (getline (MyReadFile, myText)) {
          // Output the text from the file
          cout << myText;
        // Close the file
      Cpp language logo

      Read file

      Codiga's C++ Recipes

      Read from the text file


        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.