/*****************************************************************************/ /*****************************************************************************/ /*This program reads in a number triplets, X Y Z and then prints the triplets to the screen and to a file */ /*****************************************************************************/ /*****************************************************************************/ #include //Normal Input/Output #include //File Input/Output using namespace std; int main() { //FILE variables ifstream inputfile; ofstream outputfile; char outputfilename[80] = "output1.txt"; //output FILE name //other variables double x, y, z; //OPEN the input file inputfile.open("input0.txt"); //OPEN the output file outputfile.open(outputfilename); //READ input from file, PRINT to screen & PRINT to another file //NOTE: the input command looks very similar to //cin >> x >> y >> z; inputfile >> x >> y >> z; //////////////////////////////////////////////////// //This method checks if the program has read to the //end of the file. If not, it reads a new line & //processes it. Compare this method to simplefile2.cxx //which should have identical processing, but a more //efficient implementation. //////////////////////////////////////////////////// while (! inputfile.eof()) { //cout << x << " " << y << " " << z << endl; outputfile << x << " " << y << " " << z << endl; inputfile >> x >> y >> z; } //CLOSE the input file inputfile.close(); //CLOSE the output file outputfile.close(); return 0; }