//Reads in the data file produced with ofstream_example.cpp #include <iostream> #include <math.h> #include <fstream> #define NPOINTS 100 using namespace std; main() { ifstream fin("output_file.txt"); double value, sin_of_value; // The following line reads in two numbers from a file and interprets each // as a double. It assumes that the numbers are separated by white space, // which can come in the form of tabs, spaces, carriage returns, etc. // fin >> value >> sin_of_value; // Diagnostic lines of the following type are helpful for debugging to make // sure you're reading in values correctly. // cout << "read in: " << value << "\t" << sin_of_value << endl; //To read the full file, use a while loop like this (though other methods //are also available). //The "fin >> variable" command will return as false if it fails to read //the expected values in. while (fin >> value >> sin_of_value) { cout << "read in: " << value << "\t" << sin_of_value << endl; } fin.close(); }