read-from-file in C++


Tue Jan 03 2023 05:40:47 GMT+0000 (Coordinated Universal Time)

Saved by @berasumit611 #c++

 Author:	Internshala
 Module:	Diving into C++ Programming
 Topic:		File Handling

#include <fstream>
#include <iostream>
using namespace std;

int main() {

	// The string will hold the text present in each line on the file.
	string str;

	// Create ifstream (Input File Stream) object.
	ifstream iFile;

	// Open the file."my-note.txt");

	// Use a while loop together with the getline() function to read the file line by line.
	while(!iFile.eof()) {
		getline(iFile, str);		// Reads a line.
		cout << str << endl;		// Prints the line.

	// Close the opened file.

	return 0;