// Bob Myers // numout.cpp // // Example illustrating basic file output #include #include using namespace std; int main() { ofstream fout; fout.open("datafile.txt"); if (!fout) // if the open failed { cerr << "Attempt to create file failed\n"; exit(1); } // get three values from the user int x, y, z; cout << "Type in 3 integers: "; cin >> x >> y >> z; // output the first 10 multiples of each value to the file // one set of multiples per line int i = 1; while (i <= 10) { fout << x * i << '\t'; fout << y * i << '\t'; fout << z * i << '\n'; i++; } cout << "All done!\n"; fout << '\n'; fout.close(); // Illustrates the opening of another file with the same stream fout.open("logfile.dat"); if (!fout) exit(0); fout << "Please disperse. Nothing to see here.\n"; fout << "Please move along.\n"; fout << "Go away already!\n"; fout.close(); return 0; }