// This program reads a number from a file. #include #include #include using namespace std; int main() { 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 ... "; infile >> num1; infile.close(); // close the file! cout << "Done!" << endl; cout << "The first number in the file is " << num1 << "." << endl; return 0; }