/*****************************************************************************/ /*****************************************************************************/ /*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 #include //exit() #include //setw() using namespace std; int main() { //FILE variables ifstream inputfile; ofstream outputfile; char outputfilename[80] = "output1.txt"; //other variables double x, y, z; //OPEN the input file inputfile.open("input1.txt"); if (inputfile.fail()) { cout << "Failed to open file input1.txt\n"; exit(1); } //OPEN the output file outputfile.open(outputfilename); //READ input from file, PRINT to screen & PRINT to another file while (inputfile >> x >> y >> z) { //OUTPUT SCREEN cout.setf(ios::showpoint); cout.setf(ios::fixed); cout.precision(2); cout << x << setw(8) << y << setw(8) << z << endl; //OUTPUT FILE outputfile.setf(ios::showpoint); outputfile.setf(ios::fixed); outputfile.precision(2); outputfile << x << setw(8) << y << setw(8) << z << endl; } //CLOSE the input file inputfile.close(); //CLOSE the output file outputfile.close(); return 0; }