// pgm17 INPUT FILES // We want our C++ program to get input from a file that // is stored on our disk, rather than a person typing // each piece of input. // 9/28/16 #include // include fstream to be able to use files #include #include #include using namespace std; int main() { // this defines an input file stream object ifstream inFile; // similar to cin, its an identifier that you make up inFile.open("data.txt"); // check whether input file opened successfully // if it did not work, pgm cannot get input, and exit if (!inFile) { cout << "file did not open successfully" << endl; exit(1); } // now use inFile the same way as cin int num; for (int i=0; i<5; i++) { inFile >> num; cout << num << endl; } inFile.close(); return 0; } /* Create a text file with some numbers in it. Write a C++ program that will read all of the numbers in the file, print them to the screen, and add them up and print the sum to the screen. TIME PERMITTING: Send all output both to the screen and to an output file. */