read-from-file in C++

PHOTO EMBED

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.
	iFile.open("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.
	iFile.close();

	return 0;
}
content_copyCOPY

https://github.com/Internshala-Online-Trainings/programming-with-c-and-cpp-v2/blob/master/m4-diving-into-cpp-programming/t7-file-handling/read-from-file.cpp