#include#include using namespace std; int main() { // Open file for reading ifstream infile("example.txt"); // Read from file until EOF while (!infile.eof()) { string line; getline(infile, line); cout << line << endl; } return 0; }
#includeIn this example, we use the cin object to read integers from user input until the end-of-file condition is reached. We use the eof() method implicitly by checking the return value of the cin object's extraction operator. The cpp istream eof() method is a member function of the standard c++ library.using namespace std; int main() { // Read integers from user input until EOF int num; while (cin >> num) { cout << num << endl; } return 0; }