// This program reads all the numbers from a file. #include #include #include using namespace std; int main() { const string filename = "some_numbers.txt"; int num1; ifstream infile; // instantiate file pointer object infile.open(filename); // associate file with file pointer object if (!infile) { cout << "Error opening file." << endl; return 1; // exit program with error code } cout << "Reading from file ... " << endl; while (infile >> num1) { cout << num1 << endl; } infile.close(); // close the file! cout << "Done!" << endl; return 0; }