0% found this document useful (0 votes)
2 views

Example of program input from file

The document provides a C++ program that reads a text file line by line and outputs its content to the console. It utilizes the ifstream class to open and read from a file named 'filename.txt'. The program employs a while loop with the getline() function to process each line until the end of the file is reached.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Example of program input from file

The document provides a C++ program that reads a text file line by line and outputs its content to the console. It utilizes the ifstream class to open and read from a file named 'filename.txt'. The program employs a while loop with the getline() function to process each line until the end of the file is reached.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Example of program input from file

#include <iostream>

#include <fstream>
#include <string>
using namespace std;
using namespace std;
int main()
{
// 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


MyReadFile.close();

return 0;
}

You might also like